私はObjective-Cの初心者です。可変性/不変性の双子の概念に苦労しています。私は、Programming in Objective-C 4th Edition という本を読んでいます。NSString
第15章では、不変であると述べられているクラスについて話します。次に、本はそれと矛盾するように見える例を提供します。
NSString *str1 = @"this is string A";
NSString *str2 = @"this is string B";
str2 = [str1 stringByAppendingString:str2];
NSString *res;
res = [str1 substringToIndex:3];
res = [str1 substringFromIndex:5];
res = [[str1 substringFromIndex:8]substringToIndex:6];
res = [str1 substringWithRange:NSMakeRange(8, 6)];
'res' は不変オブジェクトへのポインターですが、その値は何度か変更されています。私はポイントを完全に見逃していると思います。どんなアドバイスも、ありがたく受け取った。