2

我制作了一个继承自 NSObject 的自定义对象。假设我有一个这些对象的数组。然后我想制作另一个对象,即数组中一个对象的副本。我不想简单地指向我想要一个副本的数组中的现有对象。是否有捷径可寻?

4

1 回答 1

4

Implement the NSCopying protocol on the object, and use it as follows:

MyFoo * theCopy = [[myArray objectAtIndex:0] copy];

Note that theCopy is a retained object at this point, and should be released when you are done with it.

于 2010-10-08T12:21:41.523 回答