Grand Central Dispatch

Now that we know closures, we know how to wrap up little blocks of code and pass them around as objects. Beyond AV Foundation, we’ll find that many iOS frameworks work with closures. One of the most popular idioms is to do some work that will take an unpredictable amount of time, and then when it’s done, it can call a closure we provide to finish up. This is the completion handler pattern, and it’s frequently used for things like network access: like “Send a tweet, and when it goes through, call my closure that updates the UI and plays a sound.”

This also raises an interesting question: just who’s executing our closures anyway?

Closures play an important role in solving one of the biggest problems on a platform like ...

Get iOS 10 SDK Development, 1st Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.