繁体   English   中英

从NSMutableArray复制对象的正确方法是什么

[英]What is the correct way to copy an object from an NSMutableArray

所以我想从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

在数组中的对象上调用copy方法,然后自己释放它:

self.myObject = [[self.myMutableArray objectAtIndex:5] copy];
...
[self.myObject release];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM