来瞧瞧这个例子:

@interface Book : NSObject
@property (strong, nonatomic) NSString *title;
@end

在另一个类中,我们有一个这样的方法:

- (void)stringExample {
 NSMutableString *bookTitle = [NSMutableString stringWithString:@"Best book ever"];
 
 Book *book = [[Book alloc] init];
 book.title = bookTitle;

 [bookTitle setString:@"Worst book ever"];
 NSLog(@"book title %@", book.title);
}

也就是说修改booTitle,不再会影响字符串副本值,这是多数情况下我们想要的结果。

相关文章:

  • 2021-09-24
  • 2021-08-07
  • 2021-06-25
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-23
  • 2022-12-23
  • 2021-05-17
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
相关资源
相似解决方案