Objective-c: Questions about self = [super init]

前端 未结 8 1179
鱼传尺愫
鱼传尺愫 2020-12-12 23:01


I have seen self = [super init] in init methods. I don\'t understand why. Wouldn\'t [super init] return the superclass? And if we point

8条回答
  •  遥遥无期
    2020-12-12 23:25

    Every method that you declare has two hidden parameters: self and _cmd.

    The following method:

    - (id)initWithString:(NSString *)aString;
    

    is converted by the compiler to the following function call:

    id initWithString(id self, SEL _cmd, NSString *aString);
    

    see this link for more:

    http://www.cocoawithlove.com/2009/04/what-does-it-mean-when-you-assign-super.html

提交回复
热议问题