Created
December 26, 2014 19:39
-
-
Save bnickel/b8752e36ecc256178e91 to your computer and use it in GitHub Desktop.
Demonstrates NSURLSession's lack of localized error descriptions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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