Re: Loading NSManagedObjects across NSManagedObjectContexts in an unsaved NSPersistentDocument
Re: Loading NSManagedObjects across NSManagedObjectContexts in an unsaved NSPersistentDocument
- Subject: Re: Loading NSManagedObjects across NSManagedObjectContexts in an unsaved NSPersistentDocument
- From: Dave Zwerdling <email@hidden>
- Date: Mon, 22 Nov 2010 09:54:07 -0800
Hello again;
Well, I ran some debugging and I determined that ALL I needed was an initial save. After that, all the core data stores are up-to-date, and faults result in actual fetched data.
So, although kind of kludgy, I accepted the "Initial Save" behavior à la Garageband, where the user is required to save the document at the document's creation. I resolved this by adding the following code to my NSPersistentDocument subclass.
The code which results in the following behavior:
1) The main document window is displayed
2) The document ensures there is actually a persistent store backing the PSC. If there is, then no further action.
3) If there is no persistent store, prompt the user to save the document. This should only occur if the document has never been saved. If the document was successfully saved, no further action.
4) If the document was not successfully saved, close the document.
Like I said, this seems to be below-par. But I'm willing to accept it unless someone has a simpler/better implementation.
Dave
-(void) showWindows
{
[super showWindows];
[self ensureSaved];
}
-(void) ensureSaved
{
if([[[[self managedObjectContext] persistentStoreCoordinator] persistentStores] count] == 0)
{
[self saveDocumentWithDelegate:self didSaveSelector:@selector(document:didSave:contextInfo:) contextInfo:nil];
}
}
- (void)document:(NSDocument *)doc didSave:(BOOL)didSave contextInfo:(void *)contextInfo
{
if(doc == self)
{
if(! didSave)
{
[self close];
}
}
}_______________________________________________
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