Re: Loading NSManagedObjects across NSManagedObjectContexts in an unsaved NSPersistentDocument
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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Loading NSManagedObjects across NSManagedObjectContexts in an unsaved NSPersistentDocument
Le 21 nov. 2010 à 20:09, Dave Zwerdling a écrit : The issue lies in this: I have a background-thread reader of entities. Because it is multithreaded, it uses a separate MOC for the entities to be read. These MOCs have their persistent store coordinator the same as the document. The background thread always returns faulted objects until the persistent document is saved. If this is your problem, this is normal. Until they are saved to the persistent document, newly created objects are local to their MOC and cannot be accessed elsewhere: upon creation, they are assigned temporary IDs. Vincent___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Loading NSManagedObjects across NSManagedObjectContexts in an unsaved NSPersistentDocument
On Nov 21, 2010, at 11:37 AM, vincent habchi wrote: Le 21 nov. 2010 à 20:09, Dave Zwerdling a écrit : The issue lies in this: I have a background-thread reader of entities. Because it is multithreaded, it uses a separate MOC for the entities to be read. These MOCs have their persistent store coordinator the same as the document. The background thread always returns faulted objects until the persistent document is saved. If this is your problem, this is normal. Until they are saved to the persistent document, newly created objects are local to their MOC and cannot be accessed elsewhere: upon creation, they are assigned temporary IDs. Vincent Is there a recommended way to enhance this to do what I need? I assume I would need to create an in-memory store and keep the entities there, but how do I ensure that the documents will also make it to the persistent document on save? Dave___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Loading NSManagedObjects across NSManagedObjectContexts in an unsaved NSPersistentDocument
On Sun, Nov 21, 2010 at 2:32 PM, Dave Zwerdling zwerd...@gmail.com wrote: On Nov 21, 2010, at 11:37 AM, vincent habchi wrote: Le 21 nov. 2010 à 20:09, Dave Zwerdling a écrit : The issue lies in this: I have a background-thread reader of entities. Because it is multithreaded, it uses a separate MOC for the entities to be read. These MOCs have their persistent store coordinator the same as the document. The background thread always returns faulted objects until the persistent document is saved. If this is your problem, this is normal. Until they are saved to the persistent document, newly created objects are local to their MOC and cannot be accessed elsewhere: upon creation, they are assigned temporary IDs. Vincent Is there a recommended way to enhance this to do what I need? I assume I would need to create an in-memory store and keep the entities there, but how do I ensure that the documents will also make it to the persistent document on save? Saving means writing things to the persistent store. You cannot share unsaved objects between MOCs. Ergo, in order to get access to the objects from the other MOC, the objects must already be in the persistent store because the originating MOC has been saved. What are you trying to accomplish? --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Loading NSManagedObjects across NSManagedObjectContexts in an unsaved NSPersistentDocument
On Nov 21, 2010, at 2:47 PM, Kyle Sluder wrote: On Sun, Nov 21, 2010 at 2:32 PM, Dave Zwerdling zwerd...@gmail.com wrote: On Nov 21, 2010, at 11:37 AM, vincent habchi wrote: Le 21 nov. 2010 à 20:09, Dave Zwerdling a écrit : The issue lies in this: I have a background-thread reader of entities. Because it is multithreaded, it uses a separate MOC for the entities to be read. These MOCs have their persistent store coordinator the same as the document. The background thread always returns faulted objects until the persistent document is saved. If this is your problem, this is normal. Until they are saved to the persistent document, newly created objects are local to their MOC and cannot be accessed elsewhere: upon creation, they are assigned temporary IDs. Vincent Is there a recommended way to enhance this to do what I need? I assume I would need to create an in-memory store and keep the entities there, but how do I ensure that the documents will also make it to the persistent document on save? Saving means writing things to the persistent store. You cannot share unsaved objects between MOCs. Ergo, in order to get access to the objects from the other MOC, the objects must already be in the persistent store because the originating MOC has been saved. What are you trying to accomplish? --Kyle Sluder I have a fetcher which provides managed objects into the persistent store. I also have a class which needs to read the objects from another MOC because it is being run in a background thread. Unless the fetcher provides the managed objects, then the user saves, and only then attempts to use the functionality that requires the background thread does the MOC in the background thread become useful. Since I cannot guarantee that the user will save (nor do I want to require that procedure) I need to somehow be able to have accurate data in the background-thread MOC. Does this make sense? Dave___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Loading NSManagedObjects across NSManagedObjectContexts in an unsaved NSPersistentDocument
Le 22 nov. 2010 à 00:38, Dave Zwerdling zwerd...@gmail.com a écrit : I have a fetcher which provides managed objects into the persistent store. I also have a class which needs to read the objects from another MOC because it is being run in a background thread. You've somehow run into the same issue than me. At that point, there are, I think, two possibilities: 1. Use a single MOC and its provided mutex for accessing shared ressources (but this is strongly discouraged); 2. Create a private pool of memory in which you duplicate new objects until they are saved. Vincent ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com