【iOS】copy和mutableCopy
2015-12-02 本文已影响0人
cod_mm
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 生成了新的字符串,且是可变字符串