Ricardo Alves
Ricardo Alves

Reputation: 652

"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()

Upvotes: 0

Views: 3350

Answers (2)

virindh
virindh

Reputation: 3765

This is a common issue that occur when running on simulators. Run a device and you should see that the NSURL was created properly.

Upvotes: 0

Daij-Djan
Daij-Djan

Reputation: 50089

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

this works.

likely your real url is wrong.

Upvotes: 0

Related Questions