Skip to content

Instantly share code, notes, and snippets.

@quigebo
Created January 6, 2016 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quigebo/7cc518057d19ce66378c to your computer and use it in GitHub Desktop.
Save quigebo/7cc518057d19ce66378c to your computer and use it in GitHub Desktop.
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