wordpress-mobile/WordPress-iOS — pull request #578 by xtreme-rebecca-putinski (2013-11-18 21:17:43+00:00)
Title: Introduce Core Data background context for all data insertions/other work

The architecture is as follows:

![wordpress ios core data architecture 3](https://f.cloud.github.com/assets/1062575/1566919/860db8c4-5096-11e3-925c-862cc52f8f9d.png)

###### Benefits of this architecture
1. Less time spent blocking the main thread with the main context, like in a parent-child architecture
2. Ability to use the singleton background context for anything requiring background processing. Non-singleton contexts in other architectures need to be carefully managed so they don't fall out of scope for some tasks.
3. Two singleton contexts give clarity to developers unfamiliar with core data: do background things with the background context, UI things with the main context.
4. Disk writing is done by either, but very minimal tasks should be done with the main context. Use the background context when possible for actions that will cause a lot of disk IO (not really a problem with iOS 7 now due to Write-ahead logging.

###### Typical workflow with the background context
1. Get the reference `NSManagedObjectContext *context = [[ContextManager sharedInstance] backgroundContext];`
2. Translate any incoming objects to this context with `objectWithID:` if they've been saved prior to using them.
3. Perform inserts/fetches/deletes/updates within `performBlock:` [or `performBlockAndWait:` (blocks the main thread)]
4. Save the context with `[[ContextManager sharedInstance] saveContext:context];` within the `performBlock:`

This branch is up to date with `develop`, though Github claims the branches still cannot be merged.