Loading NSManagedObjects across NSManagedObjectContexts in an unsaved NSPersistentDocument
Loading NSManagedObjects across NSManagedObjectContexts in an unsaved NSPersistentDocument
- Subject: Loading NSManagedObjects across NSManagedObjectContexts in an unsaved NSPersistentDocument
- From: Dave Zwerdling <email@hidden>
- Date: Sun, 21 Nov 2010 11:09:00 -0800
Hi everyone,
Here's the context:
I have a Core-Data document-based application. There is an importer which creates new data to be imported into the document. When the user specifies, particular entities are then moved into the document's MOC. Because the imported can run prior to a document's save, it uses an alternative, in-memory persistent store for its MOCs. When the user choses to import the entities, they are copied to the document's MOC.
This all works fine.
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.
I have narrowed it down to a specific use case:
1) If entities are created by the importer, copied into the document, the document is unsaved, and then viewed using the same MOC, all the values are fine, and the multithreaded reader gets loaded values for entities referenced from the document's MOC.
2) If entities are created by the importer, copied, then the document is saved, the multithreaded reader gets non-faulted entities.
3) If entities are created, copied, viewed in the main thread, the document unsaved, the background-thread reader gets non-faulted entities.
HOWEVER:
4) If entities are created, copied, the document is unsaved, the data is not viewed from the document's MOC, and the background-thread reader tries to access values, it only receives faults.
Because of the above results, I believe the background-thread MOC is not loading the data appropriately until a save action occurs. This is an issue because I have no guarantee that users will save their documents prior to using the function of the App that requires background processing.
Things I have tried:
•Calling save: on the document's MOC after an entity has been copied.
•Fetching the relationships via NSFetchRequests.
•Calling willAccessValueForKey: on the faulted
Conceptually, I understand that the data cannot be fetched from the persistent store if there isn't a persistent store. In that case, where are the entities going when they exist and are fetchable from the MOC? Is there a way to create a second, temporary in-memory store for the document? Doesn't a MOC always have to have a PS via its PSC?
As you can probably tell, I've been stuck on this issue for a while. Does anyone have anything I might try?_______________________________________________
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