關於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-2025 CODEPRJ.COM