[SOLVED] Re: debugging hard-to-locate error in NSApplication delegate
[SOLVED] Re: debugging hard-to-locate error in NSApplication delegate
- Subject: [SOLVED] Re: debugging hard-to-locate error in NSApplication delegate
- From: Greg Beaver <email@hidden>
- Date: Mon, 12 Jan 2009 12:54:29 -0600
Quincey Morris wrote:
> On Jan 12, 2009, at 08:11, Greg Beaver wrote:
>
>> Does anyone have working code that shows an application delegate in a
>> core data document-based app? I'm trying to intercept
>> applicationShouldOpenUntitledFile: in order to open the last-saved
>> document. I have code that works, but it causes this error:
>>
>> *** -[NSCFArray insertObject:atIndex:]: attempt to insert nil
>>
>> some time between the setting of the delegate, which I did by inserting
>> this object into the nib and setting the delegate programmatically.
>> linking from IB did not properly set the delegate (init and
>> applicationDidFinishLaunching: were called, but
>> applicationShouldOpenUntitledFile: was never called):
>>
>> @implementation GreenwoodAppDelegate
>>
>> - (void) init
>> {
>> [super init];
>> applicationHasStarted = NO;
>> if (![[NSApplication sharedApplication] delegate]) {
>> [[NSApplication sharedApplication] setDelegate:self];
>> }
>> }
>
> This isn't going to work because your app delegate object is in your
> NIB file and is (re)created at startup by unarchiving. Therefore,
> 'initWithCoder' will be called instead or 'init'.
>
> I think you'd be better off setting your application's delegate outlet
> to the app delegate object in your main NIB file after all, and then
> trying to work out why applicationShouldOpenUntitledFile: isn't
> behaving as expected.
Hi,
I figured out the problem from:
http://www.cocoadev.com/index.pl?NSApplication
At the bottom of the page, someone had a similar issue. Turns out, I
thought my Greenwood.xib was the main nib, instead of MainMenu.xib.
Putting the app delegate in mainmenu.nib and linking in IB causes
expected behavior, and removes the exception.
Thanks for all of the help, that exception trick will be extremely
useful, I run into "track the exception source" all the time, although
usually it's much easier to debug.
Thanks,
Greg
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden