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.

Forrest
  • 122,703
  • 20
  • 73
  • 107

1 Answers1

2

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
  • 510,854
  • 105
  • 1,084
  • 1,005