Should I call [super superMethod] after or before my own code?

[sorry for weak english]

The question is simple (but I have problems expressing it and finding it on google) ...

Should I (in all such cases when I redefine a super method, not just this one) use:

- (void)viewDidLoad
{
    /*
       my code
     */

    [super viewDidLoad];
}

or

- (void)viewDidLoad
{
    [super viewDidLoad];

    /*
       my code
     */
}

or does it depend?

+5
source share
2 answers

in some cases, the order does not matter. in others, the order is critical.

Some generalizations that will help:

  • When you create a part of the state of the object ( viewDidLoadand init...), first call super.
  • when you destroy part of the state of an object ( viewDidUnloador dealloc), call superlast.
  • , , super .
+6

; -[super init] () vs -[super dealloc] ().

+1

All Articles