首页 > 其他 > 详细

给NSMutableArray添加copy属性就变成了NSArray

时间:2014-02-28 09:48:59      阅读:3061      评论:0      收藏:0      [点我收藏+]

-copy, as implemented by mutable Cocoa classes, always returns their immutable counterparts. Thus, when an NSMutableArray is sent -copy, it returns an NSArray containing the same objects.

一些参考:http://stackoverflow.com/questions/9859719/objective-c-declared-property-attributes-nonatomic-copy-strong-weak

实测:

1
2
3
4
5
6
@property(nonatomic,copy)NSMutableArray *arrayCopy;
@property(nonatomic,strong)NSMutableArray *arrayStrong;
self.arrayCopy=[[NSMutableArrayalloc]init];
self.arrayStrong=[NSMutableArrayarrayWithArray:@[@"strong1",@"strong2"]];
[self.arrayCopy addObject:@"copy1"];
[self.arrayStrong addObject:@"strong3"];

报错:

-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x100107090

而arrayStrong则不会错

给NSMutableArray添加copy属性就变成了NSArray,布布扣,bubuko.com

给NSMutableArray添加copy属性就变成了NSArray

原文:http://www.cnblogs.com/walkerwang/p/3571865.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!