Cannot assign to 'self' outside of a method in the init family
生活随笔
收集整理的這篇文章主要介紹了
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];
}
總結
以上是生活随笔為你收集整理的Cannot assign to 'self' outside of a method in the init family的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 买股票要多少钱 购买股需要多少钱
- 下一篇: 英伟达 RTX 视频超分辨率技术正式推出