美文网首页
iOS 中的字符串

iOS 中的字符串

作者: fcai | 来源:发表于2017-05-25 15:12 被阅读0次

谁能解析下这个
NSString *str1 = @"123";
NSString *str2 = @"123";
NSString *str3 = [[NSString alloc] initWithString:str1];
NSString *str4 = [str1 stringByAppendingString:@""];
NSString *str5 = [@"1" stringByAppendingString:@"23"];

NSLog(@"%p, %p", str1, str1.UTF8String);    // 0x101710610, 0x10144c4b5
NSLog(@"%p, %p", str2, str2.UTF8String);    // 0x101710610, 0x10144c4b5
NSLog(@"%p, %p", str3, str3.UTF8String);    // 0x101710610, 0x10144c4b5
NSLog(@"%p, %p", str4, str4.UTF8String);    // 0x101710610, 0x10144c4b5
NSLog(@"%p, %p", str5, str5.UTF8String);    // 0x608000053cb0, 0x60800009f340

objc_getAssociatedObject(self, key); 相同的NSString的值,通过UTF8 转换为key值就可能得不到自己想要的属性值。

相关文章

网友评论

      本文标题:iOS 中的字符串

      本文链接:https://www.haomeiwen.com/subject/rnhzxxtx.html