我希望允许对我的类对象进行深拷贝,并尝试实现copyWithZone方法,但调用[super copyWithZone:zone]
时出现错误:
error: no visible @interface for 'NSObject' declares the selector 'copyWithZone:'
@interface MyCustomClass : NSObject
@end
@implementation MyCustomClass
- (id)copyWithZone:(NSZone *)zone
{
// The following produces an error
MyCustomClass *result = [super copyWithZone:zone];
// copying data
return result;
}
@end
我该如何创建这个类的深度拷贝?