Re: Disabling auto-synthesis of property accessors.
Re: Disabling auto-synthesis of property accessors.
- Subject: Re: Disabling auto-synthesis of property accessors.
- From: Alex Zavatone <email@hidden>
- Date: Tue, 26 May 2015 13:24:08 -0400
On May 26, 2015, at 1:00 PM, Fritz Anderson wrote:
>
> On 22 May 2015, at 7:49 AM, Alex Zavatone <email@hidden> wrote:
>
>> @property (nonatomic, strong) NSString *thing;
>>
>
> Another chore in porting this code: The retention attribute should be copy, not strong.
I just typed that off the top of my head, BUT now that you mention it, I'm really happy you pointed it out.
For any nonmutable class, should I be using copy instead of strong or is this just with NSString?
> If you needed to track changes in the string, you'd use strong, but NSStrings don’t mutate; NSMutableStrings do.
>
> If you do assign a mutable string into the NSString property, the non-mutable class promises the users of your API that it won’t mutate. You need a copy to prevent changes behind your back. The performance hit is the price you pay to prevent a bug.
>
> copy is not a performance issue for NSString. It doesn’t copy anything, it just increments the retain count and returns the same pointer. (Static/global NSStrings don’t even bother to deallocate themselves.) Copying a mutable string does allocate and initialize a new object; either way, the attribute does the Right Thing.
>
Thanks. This is stuff that my brain didn't have room for when deciphering what our classes were actually doing.
Best,
Alex Zavatone
_______________________________________________
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