You can see a detailed example of how to make HTTP calls (GET, POST, etc..) in swift here.
From the link above,
You can use NSURL
, NSURLRequest
and NSURLSession
or NSURLConnection
as you'd normally do in Objective-C. Note that for iOS 7.0 and later, NSURLSession
is preferred.
Using NSURLSession
Initialize an NSURL
object and an NSURLSessionDataTask
from NSURLSession
. Then run the task with resume()
.
var url = NSURL(string: "http://www.stackoverflow.com")
let task = NSURLSession.sharedSession().dataTaskWithURL(url) {(data, response, error) in
println(NSString(data: data, encoding: NSUTF8StringEncoding))
}
task.resume()
For more detail, check the documentation for the NSURLConnectionDataDelegate
protocol