Re: Synthesised properties and additional actions
Re: Synthesised properties and additional actions
- Subject: Re: Synthesised properties and additional actions
- From: Ken Tozier <email@hidden>
- Date: Wed, 22 Jun 2011 14:49:24 -0400
For those of us new to @synthesize, would it be possible to get concrete examples of exactly what it does to create "thread safety? What is Apple doing, under the hood, to provide this?
For example: Say I have 3 properties, a float, a struct and an NSObject subclass. Written by hand they might look like
- (void) setScalar:(float) inValue
{
floatProp = inValue;
}
- (void) setStruct:(MyStruct) inValue
{
structProp = inValue;
}
- (void) setObject(id) inValue
{
objectProp = inValue;
}
If for some reason, we have to write accessors for some properties, what might those three look like if we could look into the source of properties created by synthesize?
On Jun 22, 2011, at 2:18 PM, Chris Parker wrote:
>
> On 22 Jun 2011, at 11:10 AM, Joanna Carter wrote:
>
>>> My book is about iOS 4; there is no GC in that world! ☺
>>
>> Aha! Missed that bit <embarrassed>
>>
>> But was I finally right?
>
> Consider the multi-threaded case where you want property access to be atomic (and remember, properties might not always be objects).
>
> You still would like to take advantage of the locking behavior the @synthesized getter/setter pair offers you rather than writing it yourself.
>
> The accessor synthesis doesn't just get you retain counting. Labeling and @property with the 'atomic' specifier can help in writing thread-safe accessors as well.
>
> .chris
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden