Created
June 6, 2016 10:32
-
-
Save robertmryan/2482022a929de193e1dfaea7681bc5ba to your computer and use it in GitHub Desktop.
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
func makeHTTPGetRequest(path: String, onCompletion: (JSON?, NSError?) -> ()) { | |
let request = NSMutableURLRequest(URL: NSURL(string: path)!) | |
let session = NSURLSession.sharedSession() | |
let task = session.dataTaskWithRequest(request) { data, response, error in | |
if let jsonData = data { | |
var parseError: NSError? | |
let json:JSON = JSON(data: jsonData, error: &parseError) | |
onCompletion(json, parseError) | |
} else { | |
onCompletion(nil, error) | |
} | |
} | |
task.resume() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment