iOS精品文章

iOS 对self.与_ 及copy属性与strong属性的理解

2018-05-09  本文已影响208人  菊上一枝梅
// 属性声明
@property(nonatomic, copy)NSString *str_copy_self;
@property(nonatomic, copy)NSString *str_copy_;
@property(nonatomic, strong)NSString *str_strong_self;
@property(nonatomic, strong)NSString *str_strong_;

// 测试方法
        NSMutableString *mStr1 = [[NSMutableString alloc] initWithString:@"你好"];
        self.str_copy_self = mStr1;
        _str_copy_ = mStr1;
        self.str_strong_self = mStr1;
        _str_strong_ = mStr1;
        NSLog(@"\n%p -- %@  使用copy属性self.调用的\n%p -- %@  使用copy属性_调用的\n%p -- %@  使用strong属性self.调用的\n%p -- %@  使用strong属性_调用的", self.str_copy_self, self.str_copy_self, _str_copy_, _str_copy_, self.str_strong_self, self.str_strong_self, _str_strong_, _str_strong_);
        [mStr1 appendString:@"吗"];
        NSLog(@"改变值后");
        NSLog(@"\n%p -- %@  使用copy属性self.调用的\n%p -- %@  使用copy属性_调用的\n%p -- %@  使用strong属性self.调用的\n%p -- %@  使用strong属性_调用的", self.str_copy_self, self.str_copy_self, _str_copy_, _str_copy_, self.str_strong_self, self.str_strong_self, _str_strong_, _str_strong_);
上一篇 下一篇

猜你喜欢

热点阅读