Ricardo Alves Ricardo Alves - 5 months ago 218
iOS Question

"NSURL? unable to read data" when I try getting value from String

I'm trying to get a string to pass to an NSURL but it returns

"NSURL? unable to read data"

Here is my code:

let urlPath: String = "http://test.com/get.php"
let url: NSURL =NSURL(string: urlPath)!
let request: NSURLRequest = NSURLRequest(URL: url)
let connection: NSURLConnection = NSURLConnection(request: request, delegate: self, startImmediately: true)!
connection.start()

Answer
let urlPath: String = "http://test.com/get.php" 
let url: NSURL =NSURL(string: urlPath)! 

this works.

likely your real url is wrong.