开发者

What happen when "retain" NSArray or NSMutableArray?

In the source codes

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

I understand actually following will happen

if( str 开发者_Go百科!= 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜