Andreas,
Also, in the modern runtime, you'll need to add the @synthesize to the
implementation file as well, if you don't declare the backing ivar in the
header.
Thanks,
Jamie
On Nov 2, 2011, at 10:51 AM, Jamie Pinkham wrote:
> Andreas,
>
> It most certainly indicates a semantic. That is, the generated property
> accessors and getters will retain the object versus, copying or assigning the
> object. In this case, the semantic you are trying to enforce isn't possible
> for the type you are trying to enforce it on. The error you're getting from
> the compiler would be no different than if you had indicated a retain
> semantic on a value type like NSInteger, etc. In other words, "what you're
> trying to do is invalid for the type you specified".
>
> As I indicated earlier, dispatch_queue_t isn't an object. Thus, it must be
> treated differently.
>
> If your goal is to enable dot-notation for the queue, then you must create
> the @property declaration in the header as follows:
>
> @property (nonatomic) dispatch_queue_t myQueue;
>
> And then implement your own getter and accessor (following my declared
> semantic of a nonatomic operation):
>
> - (void)setMyQueue:(dispatch_queue_t)aQueue{
> if(myQueue != aQueue){
> dispatch_retain(aQueue);
> dispatch_release(myQueue);
> myQueue = aQueue;
> }
> }
>
> - (dispatch_queue_t)myQueue{
> return myQueue;
> }
>
> - Jamie
>
> On Nov 2, 2011, at 10:30 AM, Andreas Grosam wrote:
>
>>
>> On Nov 2, 2011, at 1:33 PM, Jamie Pinkham wrote:
>>
>>> Automatic property generation doesn't support the semantics you need.
>>>
>>> You are correct that you have to use the dispatch_retain() and
>>> dispatch_release() functions; you just have write your setter and getter
>>> manually, using those functions.
>>
>> Sure, the property can't be synthesized. But even when I define setter and
>> getter in the @implementation, I can't declare the property like:
>>
>> @proprty (retain) dispatch_queue_t dispatchQueue;
>>
>> in order to indicate the semantics,
>>
>> since the compiler (clang) will refuse it with
>> "error: property with 'retain (or strong)' attribute must be of object type
>> [3]"
>>
>>
>> So, according the compiler, the property attribute "retain" does not
>> indicate a certain (and general) semantic, but assumes a specific
>> implementation applicable only for ObjC objects. Or, in other words, when I
>> state "retain", then I shall use objects and if I implement setter and
>> getter, they shall invoke retain and release.
>>
>> I would understand if the compiler would only complain about the "retain"
>> attribute if it must synthesize it for "unknown" types.
>>
>> Andreas
>>
>>
>>>
>>> -Jamie
>>>
>>> Sent from my iPhone
>>>
>>> On Nov 2, 2011, at 7:52 AM, Andreas Grosam <[email protected]> wrote:
>>>
>>>> I want to set a dispatch queue via a property. How should I set the
>>>> property's attributes when the queue is retained/released via functions
>>>> dispatch_retain() and dispatch_release()?
>>>>
>>>> Currently, since using "retain" is only possible for objects, I just
>>>> declare it like follows:
>>>>
>>>> @property (nonatomic) dispatch_queue_t dispatchQueue;
>>>>
>>>>
>>>> But here, the retain/release semantic isn't exposed. Any better ideas?
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>>
>>>> Cocoa-dev mailing list ([email protected])
>>>>
>>>> Please do not post admin requests or moderator comments to the list.
>>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>>
>>>> Help/Unsubscribe/Update your Subscription:
>>>> http://lists.apple.com/mailman/options/cocoa-dev/jamiepinkham%40me.com
>>>>
>>>> This email sent to [email protected]
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list ([email protected])
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/jamiepinkham%40me.com
>>
>> This email sent to [email protected]
>
> _______________________________________________
>
> Cocoa-dev mailing list ([email protected])
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/jamiepinkham%40me.com
>
> This email sent to [email protected]
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]