Re: NSManagedObject, NSString property retain vs copy

2015-08-01 Thread Sean McBride
On Fri, 31 Jul 2015 12:15:10 +0200, Jean-Daniel Dupas said:


 Le 30 juil. 2015 à 18:26, Fritz Anderson fri...@manoverboard.org a écrit :
 
 On 30 Jul 2015, at 11:03 AM, Trygve Inda cocoa...@xericdesign.com 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?

If it is in the property declaration, it is not an implementation
detail, it is part of the public API.

And as the receiver can’t guarantee that a passed NSString is not a
NSMutableString under the hood, it should always declare property as
copy, so the fact that some sample code (I guess this is what the op is
talking about) use retain is dubious.

This has long been a weakness in the Core Data ecosystem.  Even mogenerator 
does not have an option to make things 'copy':
https://github.com/rentzsch/mogenerator/issues/41

I might take a stab at that next week...

Cheers,

-- 

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com 
Mac Software Developer  Montréal, Québec, Canada

___

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

Re: NSManagedObject, NSString property retain vs copy

2015-07-31 Thread Jean-Daniel Dupas

 Le 30 juil. 2015 à 18:26, Fritz Anderson fri...@manoverboard.org a écrit :
 
 On 30 Jul 2015, at 11:03 AM, Trygve Inda cocoa...@xericdesign.com 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?

If it is in the property declaration, it is not an implementation detail, it is 
part of the public API.

And as the receiver can’t guarantee that a passed NSString is not a 
NSMutableString under the hood, it should always declare property as copy, so 
the fact that some sample code (I guess this is what the op is talking about) 
use retain is dubious.


___

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

Re: NSManagedObject, NSString property retain vs copy

2015-07-30 Thread Fritz Anderson
On 30 Jul 2015, at 11:03 AM, Trygve Inda cocoa...@xericdesign.com 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 (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

NSManagedObject, NSString property retain vs copy

2015-07-30 Thread Trygve Inda
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??

Trygve



___

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

Re: NSManagedObject, NSString property retain vs copy

2015-07-30 Thread Jens Alfke

 On Jul 30, 2015, at 9:03 AM, Trygve Inda cocoa...@xericdesign.com wrote:
 
 It seems Apple is using retain rather than copy for NSString properties in
 an NSManagedObject subclass.

So, you’re saying that if you store an NSMutableString into a dynamic 
NSManagedObject property, and then mutate the original string, the property’s 
value changes too? Do you have a snippet that exhibits this?

—Jens
___

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