[英]What is the correct way to copy an object from an NSMutableArray
so I want to copy an object from an NSMutableArray
: 所以我想从NSMutableArray
复制一个对象:
self.myObject = [self.myMutableArray objectAtIndex:self.currentIndex];
But when currentIndex
changes, myObject
changes to the object corresponding to the new index. 但是,当currentIndex
更改时, myObject
更改为与新索引对应的对象。
What is the best way to approach this? 解决此问题的最佳方法是什么?
Edit: 编辑:
Here's more or less what I'm trying to achieve: 这或多或少是我想要达到的目标:
self.currentIndex = 0;
self.myObject = [self.myMutableArray objectAtIndex:self.currentIndex];
self.currentIndex = 1;
//After here I want myObject to remain the same, but it doesn't
Invoke the copy
method on the object from the array, and then take care of releasing it yourself: 在数组中的对象上调用copy
方法,然后自己释放它:
self.myObject = [[self.myMutableArray objectAtIndex:5] copy];
...
[self.myObject release];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.