Is calling super in a category the same as calling it in a subclass?

后端 未结 4 1421
野性不改
野性不改 2020-11-30 09:26

Does calling [super init] do the same thing in a category as a subclass? If not, what\'s the difference?

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 09:40

    Edit: the following is built on a flawed premise, please look at josh's answer.

    not deleting, still an interesting reference for something that could potentially lead you astray.

    They are the same thing... without referencing any outside dicussions we may have had where you stated that I should ..."answer an academic question with an academic answer"

    @implementation categoryTestViewController (ShadowBar)
    - (void)viewDidAppear:(BOOL)animated {
        //draw the shadow ui nav bar
        NSLog(@"super's class = %@, self's class %@",[super class],[self class]);
        if ([self class] == [super class]) {
            NSLog(@"yeah they are the same");
        }
    }
    @end
    

    outputs:

    2011-05-29 08:06:16.198 categoryTest[9833:207] super's class = categoryTestViewController, self's class categoryTestViewController
    2011-05-29 08:06:16.201 categoryTest[9833:207] yeah they are the same
    

    and calling the [super viewDidAppear:] will result in calling nothing... not a loop, so I don't know what it is really doing there.

提交回复
热议问题