ARC には copy プロパティがありません。オブジェクトをコピーしたい場合はどうすればよいですか? 次に、テスト コードを記述します。
test.h
@property (strong, nonatomic) NSMutableString *str1;
@property (strong, nonatomic) NSMutableString *str2;
test.m
self.str1 = [[NSMutableString alloc] initWithString:@"Hello"];
self.str2 = [self.str1 copy];
[self.str2 appendString:@"World"];
NSLog(@"str1:%@,str2:%@",self.str1,self.str2);
実行すると、クラッシュしました:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with appendString:'
それで、どうすればいいですか?