首页 > 代码库 > NSString 属性为啥用copy 不用strong

NSString 属性为啥用copy 不用strong

 copy不能修改,strong可以修改,防止字符串被意外修改.demo:
——————————————————code 你要的 demo——————————————————
@property (nonatomic, copy) NSString * copystring;
@property (nonatomic, strong) NSString *strongString;
 
    NSMutableString *string = [NSMutableString stringWithString:@"a"];
   
    self.copystring = string;
    self.strongString = string;
   
    [string appendString: @"b"];
   
    NSLog(@"copyString:%@--StrongString:%@",self.copystring, self.strongString); // opyString:a--StrongString:ab
--------------------------------------------------------------------------------------------------------------------------------------------

NSString 属性为啥用copy 不用strong