edhnb
edhnb

Reputation: 2192

Saving NSManagedObjectContext in background

Is there a way to save my NSManagedObjectContext in the background, off of the main thread? The save slows down how the app is performing, as it routinely takes about 2 seconds.

Upvotes: 4

Views: 4408

Answers (1)

coverback
coverback

Reputation: 4413

Yes, there is. Apple recommends using one context per thread to achieve that.

You can also use GCD for that, but you need to make sure that queues do not share context and you will also need to pass object ID, not the objects themselves between the queues or threads.

See this blog entry for detailed instructions: http://www.cimgf.com/2011/05/04/core-data-and-threads-without-the-headache/

Upvotes: 1

Related Questions