Skip to content

Instantly share code, notes, and snippets.

@bnickel
Created December 26, 2014 19:39
Show Gist options
  • Save bnickel/b8752e36ecc256178e91 to your computer and use it in GitHub Desktop.
Save bnickel/b8752e36ecc256178e91 to your computer and use it in GitHub Desktop.
Demonstrates NSURLSession's lack of localized error descriptions.
#!/usr/bin/swift
import Foundation
let url = NSURL(string: "http://not-a-real-host")!
let request = NSURLRequest(URL: url)
var response:NSURLResponse? = nil
var error:NSError? = nil
NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: &error)
println("Good error \(error!.code) from NSURLConnection: \(error!.localizedDescription)")
let data = "hello".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
let task = NSURLSession.sharedSession().uploadTaskWithRequest(request, fromData: data)
task.resume()
while task.state != .Completed {
usleep(1)
}
println("Bad error \(task.error!.code) from NSURLSession: \(task.error!.localizedDescription)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment