簡體   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