According to Apple's documentation, the recommended way of initializing an NSWindowController subclass is by calling init() and NOT initWithWindowNibName(). The documentation goes on to say that since an NSWindowController is likely only going to work with the nib it was designed for, then have the subclass call the super initWithWindowNibName, and the subclass should log an error if any of the initWithWindowNib... methods are called.
So this is what I wrote:
- (id) init
{
NSLog(@"init()");
return [super initWithWindowNibName:@"MyDocument"];
}
- (id) initWithWindowNibName:(NSString *)windowNibName
{
NSLog(@"error...use init() instead");
return nil;
}
- (id) initWithWindowNibName:(NSString *)windowNibName owner:(id)owner
{
NSLog(@"error...use init() instead");
return nil;
}
- (id) initWithWindowNibPath:(NSString *)windowNibPath owner:(id)owner
{
NSLog(@"error...use init() instead");
return nil;
}
When it runs, I see as output:
init()
error...use init() instead
So...huh? Whats going on?
There's a stackoverflow question about init() being called twice, with the resolution being that one instance was being created via code, and the other via a nib. My nib has no controller objects in it at all.