關於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刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM