Created
June 3, 2015 07:10
-
-
Save ixqbar/69206bc9892e71ae2530 to your computer and use it in GitHub Desktop.
Swift synchronous request
This file contains 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 as! String) | |
} | |
} | |
println("start") | |
var request = Request() | |
request.send("http://linjujia.cn/", f : {(result: String)-> () in | |
println(result) | |
}) | |
println("end") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment