Skip to content

Tag Archives: Threading

Core Data and Threading

I’ve had a number of people ask me lately about the best way to handle using Core Data in a multi-threaded application. I began to put together a tutorial and sample code based on Apple’s documentation, which advises to pass NSManagedObjectIDs between threads to get around the fact that threads can’t share instances of NSManagedObjectContext or NSManagedObject. I’ve used this approach in several projects and it works.

While googling around doing research, however, I came across a post by Marcus Zarra on the Mac Developer Network.

Marcus knows Core Data really well, having written a book on the topic, so I figured I’d take a look at what Marcus had to say on the matter. I’m glad I did. Marcus illustrates a really great approach in his post that obviates the need to pass ManagedObjectIDs around between the thread in many situations. You still need to do that if you need to pass a specific object between threads, but if you’re doing something like loading or creating managed objects in the background to be displayed in a table, this is so much easier and better.

I won’t spoil the surprise, but it’s a handy tool for your Core Data toolkit. If you have any thought about using Core Data in a multi-threaded application, you should definitely check it out.

©2008-2010 Jeff LaMarche.
Continue Reading: Core Data and Threading →