如果我不覆盖“init”方法,我想知道 init 系列方法之间[ self init ]有什么不同
。self = [ super init ]
为什么人们通常使用self = [ super init ]init 系列方法?
如果我不覆盖“init”方法,我想知道 init 系列方法之间[ self init ]有什么不同
。self = [ super init ]
为什么人们通常使用self = [ super init ]init 系列方法?
[ self init ]表示您正在初始化 self 类。
和
self = [ super init ]表示初始化超类,并将返回的地址/内存位置设置为自身类。
人们习惯于self = [ super init ]所有父类最多NSObject,所以这很重要
通常人们使用 if (self = [ super init ]) {... return self;}以防万一self == nil,但我从来没有这样的事情
[self init]是不对的,因为您只是忽略了父类的初始化,这可能是导致错误的原因