> On 27 May 2015, at 13:37, Alex Zavatone <z...@mac.com> wrote:
> 
> 
> On May 27, 2015, at 6:08 AM, Uli Kusterer wrote:
> 
>> On 26 May 2015, at 19:24, Alex Zavatone <z...@mac.com> wrote:
>>> For any nonmutable class, should I be using copy instead of strong or is 
>>> this just with NSString?
>> 
>> You should consider that pattern for every class for which a mutable version 
>> exists that is a subclass of the non-mutable base class (because only in 
>> that case could someone assign a mutable object to your un-mutable 
>> property), and which implements NSCopying. For Foundation and other Apple 
>> classes that considering should lead to using copy.
> 
> For those of us who have not yet had the coffee jump start their brain cell, 
> could you possibly reword that so it's a little less obtuse?  
> 
> No offense intended, that sentence just sends my brain cell off in too many 
> directions.

I think he meant that there is no “mutableCopy” attribute, which in turn means 
that, if you do this:

@property (nonatomic,copy)              NSMutableArray*                         
pMutableArray;


NSMutableArray* myMutableArray;

myMutableArray = [[NSMutableArray alloc] init];
someObj. pMutableArray = myMutableArray;
[myMutableArray release];

Then it assigns a Non—Mutable array to pMutableArray, so use retain instead.


But if you have:

        @property (nonatomic,copy)              NSArray*                        
        pImmutableArray;
or
        @property (nonatomic,retain)            NSArray*                        
        pImmutableArray;


NSArray*        myImmutableArray;

myImmutableArray = [[NSArray alloc] init];
someObj. pMutableArray = myImmutableArray;
[myMutableArray release];

Then you end up with the same thing, except the retain counts will differ, but 
if a Mutable array is assigned using (retained), then if the Array contents 
change, then the changes will be reflected in the Array if you used retain, but 
not if you used copy.

All the Best
Dave


_______________________________________________

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