O'Reilly logo

Core Data in Swift by Marcus S. Zarra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working on the Main Queue

In general, working on the main queue has not changed from the original design. Assuming you’re working with an NSManagedObjectContext that’s configured to run on the main queue, you’d access that NSManagedObjectContext the exact same way as before.

The big difference is when your code is on another queue and you need to do some data work on the main queue. Getting that work onto the main queue has changed, fortunately for the better. This improvement is in the form of two methods: performBlock: and performBlockAndWait:.

Introducing performBlock:

The goal of performBlock: is to guarantee that a block of code is being executed on the correct queue, which is the queue that the NSManagedObjectContext is associated with. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required