Created
June 3, 2014 15:16
-
-
Save robskillington/e310ba0627293e2df91e to your computer and use it in GitHub Desktop.
Swift synchronous request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment