viewDidLoad in NSViewController?

I figured it out within minutes of posting my comment. Adding my finding as an answer because it is an example which is missing in the docs. The below code will give you the viewDidLoad method that you want. Its so easy in a way that i wonder why Apple has not implemented it yet in OS X.

- (void)viewWillLoad {
    if([NSViewController instancesRespondToSelector:@selector(viewWillLoad)]) {
        [super viewWillLoad];
    }

    ...
}

- (void)viewDidLoad {
    if([NSViewController instancesRespondToSelector:@selector(viewWillLoad)]) {
        [super viewDidLoad];
    }
}

- (void)loadView {
    BOOL ownImp = ![NSViewController instancesRespondToSelector:@selector(viewWillLoad)];

    if(ownImp) {
        [self viewWillLoad];
    }

    [super loadView];

    if(ownImp) {
        [self viewDidLoad];
    }
}

Original source: http://www.cocoabuilder.com/archive/cocoa/195802-garbage-collection-leaks-and-drains.html

Leave a Comment