Cannot assign to 'self' outside of a method in the init family
生活随笔
收集整理的這篇文章主要介紹了
Cannot assign to 'self' outside of a method in the init family
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
有時(shí)候我們重寫(xiě)父類的init方法時(shí)不注意將init后面的第一個(gè)字母寫(xiě)成了小寫(xiě),在這個(gè)方法里面又調(diào)用父類的初始化方法(self = [super init];)時(shí)會(huì)報(bào)錯(cuò),錯(cuò)誤信息如下:
error:Cannot assign to 'self' outside of a method in the init family
原因:只能在init方法中給self賦值,Xcode判斷是否為init方法規(guī)則:方法返回id,并且名字以init +大寫(xiě)字母開(kāi)頭+其他? 為準(zhǔn)則。例如:- (id) initWithXXX;
出錯(cuò)代碼:- (id) Myinit{
self = [super init];
……
}
解決方法:- (id) initWithMy
{
self = [super init];
}
總結(jié)
以上是生活随笔為你收集整理的Cannot assign to 'self' outside of a method in the init family的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 买股票要多少钱 购买股需要多少钱
- 下一篇: ScheduledExecutorSer