![](/img/trans.png)
[英]What's the correct way to store `Class` object into `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.