Parsing the Twitter Response

Inside our handleTwitterData method, we receive the raw data from the Twitter API and can use it to update our UI.

We’ll start by handing the raw data over to Foundation’s NSJSONSerialization, which can easily produce either an NSArray or NSDictionary of the parsed data, an object that may itself be a deep structure of nested arrays and/or dictionaries. Let’s do a quick sanity check by following the NSLog statement with this:

1: private​ ​func​ handleTwitterData (data: ​NSData​!,
urlResponse: ​NSHTTPURLResponse​!,
error: ​NSError​!) {
guard​ ​let​ data = data ​else​ {
5: NSLog​ (​"handleTwitterData() received no data"​)
​ ...

Get iOS 9 SDK Development 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.