Wrap-Up

Because of the complexity of closures and asynchronous code, let’s take a break here and assess what we’ve done.

We want to get at the raw Twitter data, so we ask for access to the user’s accounts and wait for that to happen (since they might be blocked on an Allow / Don’t Allow alert). If we are allowed to use the Twitter account, we send off a request, wait for that to come back, and then use NSJSONSerialization to turn the received NSData into an array of dictionaries, one entry per tweet. Both of the waiting parts are done with closures, telling the iOS frameworks what work we want them to do once they’re able.

We’ve written two closures, both using the “completion handler” pattern that is common in iOS. In the next chapter, we’re ...

Get iOS 8 SDK Development, 2nd 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.