Re: NSManagedObject, NSString property retain vs copy
Re: NSManagedObject, NSString property retain vs copy
- Subject: Re: NSManagedObject, NSString property retain vs copy
- From: Fritz Anderson <email@hidden>
- Date: Thu, 30 Jul 2015 11:26:24 -0500
On 30 Jul 2015, at 11:03 AM, Trygve Inda <email@hidden> wrote:
> It seems Apple is using retain rather than copy for NSString properties in
> an NSManagedObject subclass.
>
> I was always under the impression that copy should be used for NSString, so
> why the retain??
For an immutable string, -copy is implemented as a -retain. -copy is a guard against the receiver’s relying on the unchanging contents of a string whose contents can be changed. If the contents cannot in fact be changed, there’s no point in allocating new memory and copying the bytes into it.
It’s an implementation detail; what makes you believe it makes a difference?
— 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