Daily iOS
Persistence

Background saves and merging

You have two complaints: data saved on a background context doesn't refresh the main screen, and the other way around, values being edited on main get overwritten. How should you set up the background save to main flow in Core Data?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Save on a separate context with performBackgroundTask, then let viewContext merge the didSave notification through automaticallyMergesChangesFromParent. You solve the overwriting with a mergePolicy that merges per property and by protecting objects under edit.

Share a question