copy和strong的区别

2017-07-13  本文已影响0人  ios___developer
@property (nonatomic, strong) NSArray *sArray;
@property (nonatomic, strong) NSMutableArray *sMulArray;
//
//
NSArray *array = @[@"a"];
self.sArray = array;
//浅拷贝,仅仅指针指向array对象

 NSMutableArray *mulArray = [NSMutableArray arrayWithObject:@"aMul"]
self.sArray = mulArray;
self.sMulArray = mulArray;
//浅拷贝, 指针指向mulArray
@property (nonatomic, copy) NSArray *cArray;
@property (nonatomic, copy) NSMutableArray *cMulArray;
//
//
NSArray *array = @[@"a"];
self.cArray = array;
//浅拷贝, 指针指向array对象
NSMutableArray *mulArray = [NSMutableArray arrayWithObject:@"m"];
self.cArray = mulArray;  
self.cMulArray = mulArray;
//深拷贝, 都会创建一个新的不可变对象
//相当于self.cArray = [NSArray arrayWithObject:@"m"];
//     self.cMulArray = [NSArray arrayWithObject:@"m"];
上一篇下一篇

猜你喜欢

热点阅读