What We’ve Learned

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 going to use closures again, this time to update the user interface. But instead of waiting for things to finish, these closures will allow us to do multiple things at once, which opens the door to a lot of cool possibilities.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.225.224