大佬教程收集整理的这篇文章主要介绍了ios – 错误:’NSObject’没有可见的@interface声明选择器’copyWithZone:’,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
error: no visible @interface for 'NSObject' declares the SELEctor 'copyWithZone:' @interface MyCustomcatlass : NSObject @end @implementation MyCustomcatlass - (id)copyWithZone:(NSZone *)zone { // The following produces an error MyCustomcatlass *result = [super copyWithZone:zone]; // copying data return result; } @end
我该如何创建这个类的深层副本?
@interface MyCustomcatlass : NSObject <NSCopying>
那么方法应该是:
- (id)copyWithZone:(NSZone *)zone { MyCustomcatlass *result = [[[self class] allocWithZone:zone] init]; // If your class has any properties then do result@L_257_5@meProperty = self@L_257_5@meProperty; return result; }
NSObject不符合NSCopying协议.这就是为什么你不能调用super copyWithZone:
编辑:根据Roger的评论,我更新了copyWithZone:方法中的第一行代码.但根据其他评论,可以安全地忽略该区域.
以上是大佬教程为你收集整理的ios – 错误:’NSObject’没有可见的@interface声明选择器’copyWithZone:’全部内容,希望文章能够帮你解决ios – 错误:’NSObject’没有可见的@interface声明选择器’copyWithZone:’所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。