Re: Create and save a NSPersistentDocument from scratch
Re: Create and save a NSPersistentDocument from scratch
- Subject: Re: Create and save a NSPersistentDocument from scratch
- From: Quincey Morris <email@hidden>
- Date: Wed, 11 Nov 2009 10:01:39 -0800
On Nov 11, 2009, at 04:34, Eric Morand wrote:
- (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)
returnCode contextInfo:(void *)contextInfo {
if (returnCode == NSOKButton) {
NSPersistentDocument * newDoc = [[[NSPersistentDocument alloc]
init] autorelease];
[newDoc setFileType:@"SQLite"];
[newDoc setFileURL:[sheet URL]];
[newDoc saveDocument:self];
}
[sheet orderOut:self];
}
Seems like you're abusing NSPersistentDocument.
For a start, it seems likely you want to subclass it, not create an
instance of it. Most documents have some kind of transient state, or
method overrides, that require a subclass. It's prima facie possible
that your documents don't, so perhaps it's OK, but it's certainly
unusual.
Next, this is a non-standard -- and incorrect-looking -- way to create
a NSPersistentDocument. Is there a reason you're not using a
NSDocumentController method (such as
'openUntitledDocumentAndDisplay:error:') to create it?
Also, the file type you're specifying doesn't look likely. "SQLite"
looks like a store type, not a file type, and the store type isn't
specified this way.
Finally, you're turning the usual mechanism inside out by *first*
running the save panel yourself, then creating a new document, then
trying to save the document but *suppressing* the save panel that
would normally appear because the document is new. Is there a reason
for that?
_______________________________________________
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