我需要深度復制具有自己對象的自定義對象。我一直在閱讀,對于如何繼承NSCopying和如何使用NSCopyObject感到有些困惑。
3 回答

倚天杖
TA貢獻1828條經驗 獲得超3個贊
蘋果文檔說
copyWithZone:方法的子類版本應首先將消息發送給super,以合并其實現,除非該子類直接來自NSObject。
添加到現有答案
@interface YourClass : NSObject <NSCopying>
{
SomeOtherObject *obj;
}
// In the implementation
-(id)copyWithZone:(NSZone *)zone
{
YourClass *another = [super copyWithZone:zone];
another.obj = [obj copyWithZone: zone];
return another;
}
- 3 回答
- 0 關注
- 551 瀏覽
添加回答
舉報
0/150
提交
取消