HTTP Request in swift not working

user2874270 picture user2874270 · Feb 5, 2015 · Viewed 8.1k times · Source

I'm trying to learn about working with APIs in Swift. As a good first test, I figured I'd hit the itunes API and just return some search results. I'm in playground using the following code. I don't get any errors, but my println isn't outputting anything. Anyone know what's wrong?

Thanks!

import UIKit
import XCPlayground

XCPSetExecutionShouldContinueIndefinitely()


let url = NSURL(string: "https://itunes.apple.com/lookup?id=909253")

let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
    println(NSString(data: data, encoding: NSUTF8StringEncoding))
}

task.resume()

Answer

rv1331 picture rv1331 · Nov 21, 2016

Try adding this line of code:

URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)