On 22 May 2015, at 7:49 AM, Alex Zavatone <z...@mac.com> 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to