NSString
NSString *str = @"copy and mutableCopy";
NSLog(@"NSString: %@ %p", NSStringFromClass([str class]), str);
NSString *copyStr = [str copy];
NSLog(@"NSString copy: %@ %p", NSStringFromClass([copyStr class]), copyStr);
NSMutableString *mutableCopyStr = [str mutableCopy];
NSLog(@"NSString mutableCopy: %@: %p", NSStringFromClass([mutableCopyStr class]), mutableCopyStr);
- NSString copy 沒有生成新的字符串
- NSString mutableCopy 生成了新的字符串敢靡,且是可變的字符串
NSMutableString
NSMutableString *str0 = [@"test" mutableCopy];
NSLog(@"NSMutableString: %@: %p", NSStringFromClass([str0 class]), str0);
NSMutableString *str1 = [str0 copy];
NSLog(@"NSMutableString copy: %@: %p", NSStringFromClass([str1 class]), str1);
NSMutableString *str2 = [str0 mutableCopy];
NSLog(@"NSMutableString mutableCopy: %@: %p", NSStringFromClass([str2 class]), str2);
- NSMutableString copy 生成了新的字符串挂滓,且是不可變的字符串
- NSMutableString mutableString 生成了新的字符串,且是可變字符串
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者