NSManagedObjectContext with different processes?

You should check the merge policy concept, to manage, get and communicate the correct values of a persistent store coordinator between different contexts.

Up vote 0 down vote favorite share g+ share fb share tw.

I have two processes that are talking to the same persistent store. I save the context on one process, and I post a distributed notification. The other process sees the distributed notification, and fetches its data again, but still receives the old data.

Is there some kind of "flushing" I need to do to get the other process to get the correct data from the store? EDIT: So, it turns out that I was flushing the data correctly. NSManagedObjects have a "refreshObject:mergeChanges" method that you use to do this.

The issue appears to be timing related. Let's say I have two processes, A and B. Process A is the main process and does a save to the database.

Then Process B does a save to the database and sends a notification to Process A that it has done so, and Process A fetches the new data. I've found that if Process A's save and Process B's save are too close together, the old data is fetched by Process A even if I refresh. If I force there to be some time between the two saves, then it works out correctly.

Obviously this seems like some kind of race condition, where perhaps the notification is getting sent before the data is actually getting saved to the database, however, the notification gets sent in the didSave method of the managed object, at which point the context has already saved. Objective-c cocoa core-data nsmanagedobject nsmanagedobjectcontext link|improve this question edited Oct 21 '11 at 2:23 asked Oct 20 '11 at 3:23JPC1,106315 84% accept rate.

You should check the merge policy concept, to manage, get and communicate the correct values of a persistent store coordinator between different contexts. Here -> developer.apple.com/library/mac/#documen... That should resolve the problem. Hope this can help.

That's what I was looking for, thanks – JPC Oct 20 '11 at 4:59 Ah turns out that this is not quite what I was looking for – JPC Oct 21 '11 at 2:19.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions