Re: NSDocumentController Problem
Re: NSDocumentController Problem
- Subject: Re: NSDocumentController Problem
- From: Nick Zitzmann <email@hidden>
- Date: Tue, 3 Mar 2009 11:30:46 -0700
On Mar 3, 2009, at 4:39 AM, 陈清华 wrote:
I am transferring my application to Snow.
And the first rule of Fight Club is...
Code to invoke:
- (void) applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSError *error = [[NSError alloc] init];
But I don't think I'm violating any NDAs by telling you that you've
made several mistakes with this code. First of all, you should not be
creating an NSError here, because you're only leaking memory (unless
you turned on GC). I would recommend just setting it to nil.
NSDocumentController *docController = [NSDocumentController
sharedDocumentCOntroller];
@try
{
[docController openUntitledDocumentAndDisplay:YES error:error];
You need to pass in a pointer to the NSError pointer, not the NSError
pointer itself.
}
@catch(NSException *e)
{
NSLog([e description]);
Don't ever do this. NSLog() takes a varargs string, so if there is a %
in the description, then the app will crash. Instead, do this:
NSLog(@"%@", e);
}
@finally
{
[error release];
}
}
You need to take this out as well, since if error is set to anything
after you passed along the pointer to the pointer, then you'll over-
release the object.
Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
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