let url =NSURL(string: "https://itunes.apple.com/search?term=apple&media=software") let task =NSURLSession.sharedSession().dataTaskWithURL(url!) { data, res, err in iflet data = data { do { let dic =tryNSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers) as!NSDictionary let array = dic["results"] as!NSArray
for appDic in array { print("trackName \(appDic["trackName"])") } } catch {
let url =NSURL(string: "https://itunes.apple.com/search?term=apple&media=software") let urlRequest =NSURLRequest(URL: url!, cachePolicy: .ReturnCacheDataElseLoad, timeoutInterval: 30)
let task =NSURLSession.sharedSession().downloadTaskWithRequest(urlRequest) { (location:NSURL?, res:NSURLResponse?, err:NSError?) -> Voidiniflet location = location { let data =NSData(contentsOfURL: location) iflet data = data { do { let dic =tryNSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers) as!NSDictionary let array = dic["results"] as!NSArray
for appDic in array { print("trackName \(appDic["trackName"])") } } catch { } } } } task.resume()
let sessionConfiguration =NSURLSessionConfiguration.defaultSessionConfiguration() sessionConfiguration.timeoutIntervalForRequest =1 let session =NSURLSession(configuration: sessionConfiguration)
let url =NSURL(string: "https://itunes.apple.com/search?term=apple&media=software") let urlRequest =NSURLRequest(URL: url!) let task = session.dataTaskWithRequest(urlRequest) { data, res, err in