ios - Core-Data: Parent context changes not being merged into child context -
my situation is: have multi-threaded app core-data database, managing multiple contexts. in context hieratchy have root saving context, , child contexts fetch data , make/save changes.
- context -> root parent context
- context b -> child context of a
- context c -> child context of a
context b used fetch data , displayed in view controller's view.
context c used save changes in background thread.
the problem when make changes in context c, save context c , a, changes not propagated, or merged, context b. changes correctly persisted in context , c, not in b.
i thought default behaviour changes in parent context propagated it's child context b, it's not happening. correct way achieve this?
if working on ios 10 project can try setting automaticallymergeschangesfromparent
property on context b true
.
for older projects have merge changes yourself:
- observe
nsmanagedobjectcontextdidsave
notification. make sure use context c object when subscribing. otherwise receive notifications context has been saved, not context c. - use
nsmanagedobjectcontext.mergechanges(fromcontextdidsave:)
update context b. objective-c selector-mergechangesfromcontextdidsavenotification:
Comments
Post a Comment