views:

18

answers:

1

In the source codes

@property(retain) NSString* str;
@sythesize str;
self.str = newStr;

I understand actually following will happen

if( str != newStr ){
     [str release];
     str = [newStr retain]; 
}

So how about the case for NSArray or NSMutableArray ? Seem like it is complex,shallow copy and deep copy should be considered.

+1  A: 

It's the same. Setting a property only changes the ownership of that array, not the content of the array (the content is owned by the same array). Therefore, only the array needs to be -retain'ed.

In fact, the runtime doesn't care about the specific Objective-C type of the property. The same setter procedure will be applied to every @property(retain) properties.

To make the setter perform shallow copying, make it @property(copy). There no way to make it deep-copy.

KennyTM