Re: Disabling auto-synthesis of property accessors.
Re: Disabling auto-synthesis of property accessors.
- Subject: Re: Disabling auto-synthesis of property accessors.
- From: Fritz Anderson <email@hidden>
- Date: Tue, 26 May 2015 12:00:28 -0500
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.
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.
— F
_______________________________________________
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