所以我想复制NSMutableArray
:
self.myObject = [self.myMutableArray objectAtIndex:self.currentIndex];
但是当currentIndex
更改时,myObject
会更改与新索引对应的对象。
最好的方法是什么?
修改
这里或多或少是我想要实现的目标:
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
答案 0 :(得分:6)
从数组中调用对象的copy
方法,然后自己解决它:
self.myObject = [[self.myMutableArray objectAtIndex:5] copy];
...
[self.myObject release];