黑马程序员技术交流社区
标题:
NSString的问题,求大神指教
[打印本页]
作者:
wtj900
时间:
2015-9-13 20:30
标题:
NSString的问题,求大神指教
求大神指教,s2,s3,s5的值为什么是这样的?
NSString *s1 = @"abc";
NSString *s2 = [NSString stringWithFormat:@"age is %d",10];
NSString *s3 = [[NSString alloc] initWithFormat:@"age is %i",20];
NSString *s5 = [[NSString alloc] initWithFormat:@"age is %i",30];
NSMutableString *s4 = [s2 mutableCopy];
NSLog(@"s1 = %zi",s1.retainCount);
NSLog(@"s2 = %zi",s2.retainCount);
NSLog(@"s3 = %zi",s3.retainCount);
NSLog(@"s5 = %zi",s5.retainCount);
NSLog(@"s4 = %zi",s4.retainCount);
运行出来的结果:
2015-09-13 20:26:24.251 copy[1594:137828] s1 = -1
2015-09-13 20:26:24.252 copy[1594:137828] s2 = -1
2015-09-13 20:26:24.252 copy[1594:137828] s3 = -1
2015-09-13 20:26:24.252 copy[1594:137828] s5 = 1
2015-09-13 20:26:24.252 copy[1594:137828] s4 = 1
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2