copy一个数组的方法
来源:互联网 发布:淘宝客公众号 编辑:程序博客网 时间:2024/05/27 14:13
NSArray *rr = [NSArray arrayWithObjects:@"aa", @"ef", @"va", nil];
NSArray *r1 = rr; //rr的引用计数还是1,因为NSArray是一个常量
NSMutableArray *dd = [NSMutableArray arrayWithObjects:@"e", @"v", nil];
NSMutableArray *r2 = dd; //rr的引用计数还是2,因为NSMutableArray不是一个常量
NSArray *newArray = [NSMutableArray arrayWithArray:oldArray];
NSArray *newArray = [[[NSMutableArray alloc] initWithArray:oldArray] autorelease];
NSArray *newArray = [[oldArray mutableCopy] autorelease];
NSMutableArray *newArray = [[[NSMutableArray alloc] initWithArray:oldArray copyItems:YES] autorelease];
NSArray *_newArray = [NSArray arrayWithArray:_oldArray];
or if you prefer better, you can use:
NSArray *_newArray = [[NSArray alloc] initWithArray:_oldArray];
(in that case the object of the first array won't be copied, that get only a retain front he second
NSArray
, you can remove the object from any array it won't affect the other array, but if you change any object in any NSArray it will be changed in the other one as well because there is both of the old and the new array is working with the same instance of the objects.)if your plan is to make another instance of the old objects in the new array:
NSArray *_newArray = [[NSArray alloc] initWithArray:_oldArray copyItems:true];
if you are using the ARC, you won't need to do anything else, if you are not, in the case of both
-initWithArray:
or-initWithArray:copyItems:
you should use the[_newArray release];
to release the array after you don't want to use anymore.
- copy一个数组的方法
- JS 数组操作的方法--COPY
- 数组copy方法
- 自己写的一个相同属性copy的方法
- Copy文件的方法
- UIImage的copy方法
- copy的set方法
- 自定义方法copy数组 和 Java类库对数组复制的支持
- 自定义方法copy数组 和 Java类库对数组复制的支持
- python的copy.copy()和copy.deepcopy()方法
- 一个Marshal.Copy的问题
- 对一个KotlinAPP的copy
- copy属性的一个好处
- surface copy 的几个方法
- 深度copy的实现方法
- object-c的copy方法
- 需要一个1000000的数组实现方法
- 打散一个二维数组的方法
- 【收藏】cocos2d-x学习资源汇总
- 打开IE浏览器的时候老提示计算机的某个程序破坏了度Internet Explor默认搜索提供程序的设置
- C++读写ini文件记录总结
- [jQuery]使用jQuery.Validate进行客户端验证(中级篇-上)——不使用微软验证控件的理由
- 书单
- copy一个数组的方法
- 改变Div的顺序,页面跳转,css、avascript加入到html的方式
- map与vector,typedef与define
- [jQuery]使用jQuery.Validate进行客户端验证(初级篇)——不使用微软验证控件的理由
- md5sum命令
- [Accessibility] Missing contentDescription attribute on image
- MySQL单列索引和联合索引
- 机房收费-小功能的实现
- 越狱开发ios应用发布真机测试(无需注册账号)