@property (nonatomic, strong) NSString *myStrongStr;
@property (nonatomic, copy) NSString *myCopyStr;
1.原对象不可变时,两种情况下都只是指针拷贝,计数+1。
NSString *originStr = @"11";
self.myCopyStr = originStr;
self.myStrongStr = originStr;
NSLog(@"originStr: %p", originStr);
NSLog(@"myCopyStr: %p", self.myCopyStr);
NSLog(@"myStrongStr: %p", self.myStrongStr);
2017-09-21 17:56:58.489 iOSLockDemo[40745:2801462] originStr: 0x10ba4a078
2017-09-21 17:56:58.490 iOSLockDemo[40745:2801462] myCopyStr: 0x10ba4a078
2017-09-21 17:56:58.490 iOSLockDemo[40745:2801462] myStrongStr: 0x10ba4a078
2.原对象可变时,strong修饰的对象,是指针拷贝,引用计数+1;copy修饰的对象是内存拷贝,生成新对象。
NSMutableString *originStr = [@"11" mutableCopy];
self.myCopyStr = originStr;
self.myStrongStr = originStr;
NSLog(@"originStr: %p", originStr);
NSLog(@"myCopyStr: %p", self.myCopyStr);
NSLog(@"myStrongStr: %p", self.myStrongStr);
2017-09-21 18:04:44.904 iOSLockDemo[40919:2812754] originStr: 0x60000006d780
2017-09-21 18:04:44.904 iOSLockDemo[40919:2812754] myCopyStr: 0xa000000000031312
2017-09-21 18:04:44.905 iOSLockDemo[40919:2812754] myStrongStr: 0x60000006d780