core data - Resolving an NSManagedObject conflict with multiple threads, relationships, and pointers -


i'm having conflict when saving bunch of nsmanagedobjects via outside thread. starters, can tell following:

  1. i'm using separate moc each thread.
  2. the mocs share same persistent store coordinator.
  3. it's outside thread modifying 1 or many of records i'm saving.

ok, out of way, here's i'm doing.

in outside thread, i'm doing computation , updating single value in bunch of managed objects. looking object in persistent store primary key, modifying single decimal property, , calling save on bunch @ once.

in meantime, believe main thread doing updating of own.

when outside thread big save on managed object context, exception thrown stating large number of conflicts. of conflicts seem centered around single relationship on each record. though managed object in persistent store , outside thread share same objectid relationship, don't share same pointer. based on see, that's thing that's different between objects in nsmergeconflict debug output.

it makes sense me why 2 objects have relationships different pointers -- they're in different threads. however, understand apple's documentation, thing cached when object first retrieved persistent store global ids. so, 1 think when run save on outside thread moc, compares objectids, sees they're same, , lets through.

so, can tell me why i'm getting conflict?

per documentation in concurrency core data chapter of the core data programming guide, recommended configuration contexts share same persistent store coordinator, not same persistent store.

also, section track changes in other threads using notifications of same chapter states if you're tracking updates nsmanagedobjectcontextdidsavenotification send -mergechangesfromcontextdidsavenotification main thread's context can merge changes. if you're tracking nsmanagedobjectcontextdidchangenotification external thread should send object ids of modified objects main thread send -refreshobject:mergechanges: context each modified object.

and really, should know if main thread performing updates through controller, , propagate changes in manner in opposite direction.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -