【发布时间】:2013-06-27 13:32:39
【问题描述】:
我正在尝试制作 NSMutableArray 的深层副本,其对象是类似于此的自定义类的实例:
@interface CustomParent : NSObject
@property NSInteger Id;
@property (strong, nonatomic) NSString *IdStr;
@property (weak, nonatomic) NSDate *Date;
@property (strong, nonatomic) NSMutableArray *CustomChildren;
@property (strong, nonatomic) CustomType *Type;
@property float Value;
@end
我知道有很多关于复制对象的帖子,但我没有找到获取具有集合成员或属性的对象的完整副本的示例。 NSMutableArray *dstArray = [[NSMutableArray alloc] initWithArray:srcArray copyItems:YES]; 引发涉及 copyWithZone 方法的异常。
我该怎么做?谢谢!
【问题讨论】:
-
你的意思可能是
NSCopying -
@AppsDev,建议的解决方案运气好吗?
-
@GabrielePetronella 我阅读了您提到的帖子,它似乎有效,谢谢!
-
@LescaiIonel 我之前尝试过
NSCoding,复制许多连接到一个类的对象需要很长时间。 ThinsNSCopying应该更快。
标签: ios objective-c nsmutablearray deep-copy