This is my question; I want to get some data from an URL, this is the code:
let internetURL = NSURL(string:"http://www.example.org")
let siteURL = NSURLRequest(URL: internetURL!)
let siteData = NSURLConnection(request: siteURL, delegate: nil, startImmediately: true)
let strSiteData = NSString(data: siteData, encoding: NSUTF8StringEncoding)
when I write this, XCode give me the following error:
Extra argument 'encoding' in call
on the last line. How can I do?
The error message sucks.
If you run it in playground, you can see that siteData is an NSURLConnection object. Not an NSData object. That's why it won't compile.
The correct way to create a string from a URL is:
Using
NSURLConnection
properly is complicated as it's a low level API that should only be used if you're doing something unusual. Using it properly requires you to understand and interact with the TCP/IP stack.