//联系人:石虎QQ:1224614774昵称:嗡嘛呢叭咪哄
一、概念
@interfaceA : NSObject
- (instancetype)initDesignatedNS_DESIGNATED_INITIALIZER;
- (instancetype)initUndesignated;
@end
@implementationA
- (instancetype)init
{
return([selfinitUndesignated]);
}
- (instancetype)initDesignated
{
return(self= [superinit]);
}
- (instancetype)initUndesignated
{
return(self= [selfinitDesignated]);
}
@end
@interfaceB : A
- (instancetype)initDesignatedBNS_DESIGNATED_INITIALIZER;
- (instancetype)initUndesignatedB;
@end
@implementationB
- (instancetype)initDesignated
{
return[selfinitUndesignatedB];
}
- (instancetype)initDesignatedB
{
return(self= [superinitDesignated]);
}
- (instancetype)initUndesignatedB
{
return([selfinitDesignated]);
}
@end
最后一个函数initUndesignatedB里面这样调用不会有警告,其实很好理解。
1.因为self没有实现initUndesignated,所以会调用super的initUndesignated方
2.super的initUndesignated需要调用initDesignated方法
3.子类实现了initDesignated方法,所以最终回调用到self的initDesignated方法,这当然不会有什么问题了