I'm having a similar issue when trying to download a file via URL in Xcode Beta 5 and Swift 2 running iOS9
Would really appreciate any help as I am going crazy trying to find out what it doesn't like about the code in swift2 ? The documentation says the method signature has not changed. I click on the code suggestion to get the completion handlers then it gives me errors. I took the code back into Swift 1.2 in Xcode 6.4 and it ran straight away 😕
This code runs fine in iOS 8.4 Xcode 6.4
let messageURL = NSURL(string: "http:/
let sharedSession = NSURLSession.sharedSession()
let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(messageURL!,
completionHandler: {
(location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in
var urlContents = NSString(contentsOfURL: location, encoding: NSUTF8StringEncoding, error: nil)
println("response : \(response)")
println(urlContents)
})
downloadTask.resume()
I get a response and urlContents printed.
The same code for iOS9 gives me a compile error complaining about the method signature of the downloadTaskWithURL function
let messageURL = NSURL(string: "http:/
let sharedSession = NSURLSession.sharedSession()
let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(messageURL!,
completionHandler: {
(location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in
var urlContents = NSString(contentsOfURL: location, encoding: NSUTF8StringEncoding, error: nil)
print("response : \(response)")
print(urlContents)
})
downloadTask.resume()
The compile error is shown below:
https://drive.google.com/file/d/0B7a9zgAH2mBfeHM0TjE5MF91RzA/view?usp=sharing
http://i.imgur.com/AW9ge7R.png
Successful code in iOS8.4:
http://i.imgur.com/P17JROM.png