emersonbroga
6/3/2014 - 3:16 PM

Swift synchronous request

Swift synchronous request


class Request : NSObject {
    func send(url: String, f: (String)-> ()) {
        var request = NSURLRequest(URL: NSURL(string: url))
        var response: NSURLResponse?
        var error: NSErrorPointer = nil
        var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: error)
        var reply = NSString(data: data, encoding: NSUTF8StringEncoding)
        f(reply)
    }
}

var request = Request()
request.send("http://google.com", {(result: String)-> () in
    println(output)
})