0
votes

I have integrated iCloud into my application and I am able to save the iCloud changes successfully in my persistent store. Currently, I am doing the following :-

// my NSManagedObjectContext (used by main thread) is declared as NSMainQueueConcurrencyType

  1. Listen for iCloud Notification
  2. Merge changes into the main managedObjectContext using performBlock

I have also seen the following approach :-

// NSManagedObjectContext (used by main thread) is declared as NSMainQueueConcurrency Type

  1. Create a temporary managed object context having NSPrivateQueueConcurrency type as its concurrency type in the method executed when iCloud sends notification
  2. Make the main MOC as the parent of the temporary MOC
  3. Do save on temporary MOC (This will push changes to main MOC)
  4. Do save on main MOC using performBlock

So, both approaches are using performBlock to save the changes to the persistent store. So, is there any particular advantage / disadvantage to any approach ?

1

1 Answers

0
votes

Max,

Everything is a tradeoff. The big win from using a child MOC is the implicit caching of state from the parent and that saves are quite fast. (They're fast because they just push data up the child-parent stack. You still need to save from the parent to persist the data.)

The downside of your architecture is that the saves from afar happen on your main loop. If they take much time, and saves can sometimes take an inordinate amount of time, the UI responsiveness is hit.

In answer to your question, the -performBlock: calls don't change these facts. All they do is defer processing to the next iteration of the main loop.

Andrew