My NSWindowController has this code:
- (id)init {
[self initWithWindowNibName:@"MyWindow"];
[self loadWindow];
return self;
}
- (void)windowDidLoad
{
[super windowDidLoad];
NSWindow *window = [self window];
NSAssert(window != nil, @"Can’t get window!");
// do some stuff
}
The NSAssertfails.
Why?
How can I get the window?
There are two issues here. Firstly, your initialiser is missing the assignment to
self:Secondly, and the probable reason that your assertion is failing, is that you have not connected the
windowoutlet of File’s Owner in your nib file to the window object. This means that your window controller doesn’t know what object the window property points to.If you don’t understand how to set outlets in Interface Builder then you have a lot of learning to do and you should do a simple tutorial before you do anything else, because understanding how outlets and actions work is fundamental to being able to program with Cocoa.