关于error:Cannot assign to 'self' outside of a method in the init family


      有时候我们重写父类的init方法时不注意将init后面的第一个字母写成了小写,在这个方法里面又调用父类的初始化方法(self = [super init];)时会报错,错误信息如下:error:Cannot assign to 'self' outside of a method in the init family

原因:只能在init方法中给self赋值,Xcode判断是否为init方法规则:方法返回id,并且名字以init+大写字母开头+其他  为准则。例如:- (id) initWithXXX;

出错代码:- (id) Myinit{

 self = [super init];

 ……

}

解决方法:- (id) initWithMy

{

 self = [super init];

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 AttributeError: cannot assign module before Module.__init__() call pycharm提示This inspection detects instance attribute definition outside __init__ method ssh登录过程中 出现 unsupport gssapiauthentication及pscp传输文件出现 ssh_init: Network error: Cannot assign requested address错误 self参数 - __ init__ ()方法 super(Net, self).__init__() 安装不可描述服务端socket.error: [Errno 99] Cannot assign requested address错误: vue运行报错error:Cannot assign to read only property 'exports' of object '#' SyntaxError: Cannot use import statement outside a module Cannot assign requested address 的问题 Spring InitializingBean和init-method Cannot resolve method
 
粤ICP备18138465号  © 2018-2026 CODEPRJ.COM