字符串中的retain与copy
2016-04-07 17:48
513 查看
NSMutableString *mStr = [NSMutableString
string];
[mStr setString:@"我没变"];
self.retainStr = mStr;
self.cpStr = mStr;
self.retainMStr = mStr;
self.cpMStr = mStr;
NSLog(@"retainStr:%@",
self.retainStr);
NSLog(@"copyStr:%@",
self.cpStr);
NSLog(@"retainMStr:%@",
self.retainMStr);
NSLog(@"copyMStr:%@",
self.cpMStr);
NSLog(@"\n");
[mStr setString:@"我变了"];
NSLog(@"retainStr:%@",
self.retainStr);
NSLog(@"copyStr:%@",
self.cpStr);
NSLog(@"retainMStr:%@",
self.retainMStr);
NSLog(@"copyMStr:%@",
self.cpMStr);
NSLog(@"\n");
NSString *str =
@"我来了";//[[NSString alloc] initWithFormat:@"我来了"];//两种方式都一样。
self.retainStr = str;
self.cpStr = str;
self.retainMStr = [str
mutableCopy];
self.cpMStr = [str
mutableCopy];
NSLog(@"retainStr:%@",
self.retainStr);
NSLog(@"copyStr:%@",
self.cpStr);
NSLog(@"retainMStr:%@",
self.retainMStr);
NSLog(@"copyMStr:%@",
self.cpMStr);
NSLog(@"\n");
str =@"我走了";//[[NSStringalloc]
initWithFormat:@"我走了"];//两种方式都一样
NSLog(@"retainStr:%@",
self.retainStr);
NSLog(@"copyStr:%@",
self.cpStr);
NSLog(@"retainMStr:%@",
self.retainMStr);
NSLog(@"copyMStr:%@",
self.cpMStr);
NSLog(@"\n");
结果:
2016-04-07 17:39:00.780 FMDBTest[1305:504297] retainStr:我没变
2016-04-07 17:39:00.780 FMDBTest[1305:504297] copyStr:我没变
2016-04-07 17:39:00.780 FMDBTest[1305:504297] retainMStr:我没变
2016-04-07 17:39:00.780 FMDBTest[1305:504297] copyMStr:我没变
2016-04-07 17:39:00.780 FMDBTest[1305:504297]
2016-04-07 17:39:00.780 FMDBTest[1305:504297] retainStr:我变了
2016-04-07 17:39:00.780 FMDBTest[1305:504297] copyStr:我没变
2016-04-07 17:39:00.781 FMDBTest[1305:504297] retainMStr:我变了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] copyMStr:我没变
2016-04-07 17:39:00.781 FMDBTest[1305:504297]
2016-04-07 17:39:00.781 FMDBTest[1305:504297] retainStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] copyStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] retainMStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] copyMStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297]
2016-04-07 17:39:00.781 FMDBTest[1305:504297] retainStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] copyStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] retainMStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] copyMStr:我来了
2016-04-07 17:39:00.782 FMDBTest[1305:504297]
string];
[mStr setString:@"我没变"];
self.retainStr = mStr;
self.cpStr = mStr;
self.retainMStr = mStr;
self.cpMStr = mStr;
NSLog(@"retainStr:%@",
self.retainStr);
NSLog(@"copyStr:%@",
self.cpStr);
NSLog(@"retainMStr:%@",
self.retainMStr);
NSLog(@"copyMStr:%@",
self.cpMStr);
NSLog(@"\n");
[mStr setString:@"我变了"];
NSLog(@"retainStr:%@",
self.retainStr);
NSLog(@"copyStr:%@",
self.cpStr);
NSLog(@"retainMStr:%@",
self.retainMStr);
NSLog(@"copyMStr:%@",
self.cpMStr);
NSLog(@"\n");
NSString *str =
@"我来了";//[[NSString alloc] initWithFormat:@"我来了"];//两种方式都一样。
self.retainStr = str;
self.cpStr = str;
self.retainMStr = [str
mutableCopy];
self.cpMStr = [str
mutableCopy];
NSLog(@"retainStr:%@",
self.retainStr);
NSLog(@"copyStr:%@",
self.cpStr);
NSLog(@"retainMStr:%@",
self.retainMStr);
NSLog(@"copyMStr:%@",
self.cpMStr);
NSLog(@"\n");
str =@"我走了";//[[NSStringalloc]
initWithFormat:@"我走了"];//两种方式都一样
NSLog(@"retainStr:%@",
self.retainStr);
NSLog(@"copyStr:%@",
self.cpStr);
NSLog(@"retainMStr:%@",
self.retainMStr);
NSLog(@"copyMStr:%@",
self.cpMStr);
NSLog(@"\n");
结果:
2016-04-07 17:39:00.780 FMDBTest[1305:504297] retainStr:我没变
2016-04-07 17:39:00.780 FMDBTest[1305:504297] copyStr:我没变
2016-04-07 17:39:00.780 FMDBTest[1305:504297] retainMStr:我没变
2016-04-07 17:39:00.780 FMDBTest[1305:504297] copyMStr:我没变
2016-04-07 17:39:00.780 FMDBTest[1305:504297]
2016-04-07 17:39:00.780 FMDBTest[1305:504297] retainStr:我变了
2016-04-07 17:39:00.780 FMDBTest[1305:504297] copyStr:我没变
2016-04-07 17:39:00.781 FMDBTest[1305:504297] retainMStr:我变了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] copyMStr:我没变
2016-04-07 17:39:00.781 FMDBTest[1305:504297]
2016-04-07 17:39:00.781 FMDBTest[1305:504297] retainStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] copyStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] retainMStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] copyMStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297]
2016-04-07 17:39:00.781 FMDBTest[1305:504297] retainStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] copyStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] retainMStr:我来了
2016-04-07 17:39:00.781 FMDBTest[1305:504297] copyMStr:我来了
2016-04-07 17:39:00.782 FMDBTest[1305:504297]
相关文章推荐
- MYSQL启动错误之[ERROR] Failed to open log (file './mysql-bin.000039', errno 2)
- 人机五子棋(AI算法有瑕疵)
- MainWindow.h
- mybait的文件配置
- 华为RAID 1阵列卡设置教程图文详解
- 进程 、进程组、会话、控制终端之间的关系 (转载 http://blog.csdn.net/yh1548503342/article/details/41891047)
- SCU3033 Destroying a Painting(最小费用最大流)
- 涂鸦|绘制|draw|paint|view的绘制|undo|redo|恢复|撤销|保存
- apt-get couldn't be verified because the public key is not available: NO_PUBKEY XXX
- 7.5 mail_copy函数:向文件系统写入邮件
- 7.4 deliver_mailbox_file函数:以mbox格式接收邮件
- 7.4 deliver_mailbox_file函数:以mbox格式接收邮件
- 7.3 deliver_maildir函数:以Maildir格式接收邮件
- Ehcache项目启动时报Update check failed异常的解决方法
- 6.6 移信和 fairness策略
- 6.3.3 sendmail的别名文件和.forward文件
- RAID阵列的迁移
- LeetCode(31)-Factorial Trailing Zeroes
- LeetCode(31)-Factorial Trailing Zeroes
- LeetCode(31)-Factorial Trailing Zeroes