Created
January 6, 2016 16:55
-
-
Save quigebo/7cc518057d19ce66378c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import XCPlayground | |
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true | |
let searchTerm = "philip+glass" | |
let url = NSURL(string: "https://itunes.apple.com/search?term=\(searchTerm)") | |
let request: NSURLRequest = NSURLRequest(URL: url!) | |
let session = NSURLSession.sharedSession() | |
let task: NSURLSessionDataTask = session.dataTaskWithRequest(request, completionHandler: { | |
(data, response, error) in | |
if response == nil { | |
print("Timeout") | |
} else { | |
do { | |
let jsonDict = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions(rawValue: 0)) as? NSDictionary | |
if let jsonDict = jsonDict { | |
// BUILD OBJECTS | |
} else { | |
// error handling | |
} | |
} catch let error as NSError { | |
// error handling | |
} | |
} | |
} | |
) | |
task.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment