-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

实测:

@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则不会错

相关文章:

  • 2022-02-01
  • 2021-10-09
  • 2021-12-30
  • 2022-12-23
  • 2021-05-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
猜你喜欢
  • 2021-07-23
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2022-01-10
相关资源
相似解决方案