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: Eric Morand <email@hidden>
- Date: Wed, 11 Nov 2009 21:41:23 +0100
Thanks Quincey,
Your code pointed me in the right direction : I needed to create a persistent store (of type NSSQLiteStoreStype) like in your example and add it to the newly created document context.
I also replaced the file type "SQLite" with the correct file type defined in my plist (MyDocument). Now, it works perfectly !
Here is the code I now use :
- (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo {
if (returnCode == NSOKButton) {
NSError * error = nil;
SBDocument * newDoc = [[[SBDocument alloc] init] autorelease];
NSManagedObjectContext * moc = [newDoc managedObjectContext];
[[moc persistentStoreCoordinator] addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[sheet URL] options:nil error:&error];
//[newDoc setFileType:@"ShoppingBagDocument"];
//[newDoc setFileURL:[sheet URL]];
//[newDoc saveDocument:nil];
[newDoc saveToURL:[sheet URL] ofType:@"MyDocument" forSaveOperation:NSSaveOperation error:&error];
}
[sheet orderOut:self];
}
I've replaced the three commented lines with the saveToURL... call which looks cleaner to me. But it also works with the three commented lines.
Again, thanks a lot for your valuable help. I would have been stuck for a long time if you did not pointed me to the right direction.
Kind regards,
Eric.
_______________________________________________
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