Created
October 19, 2014 19:43
-
-
Save toast38coza/eb8da7d90aab94f44a3c to your computer and use it in GitHub Desktop.
Call a JSON endpoint with swift
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
let url = NSURL(string: "http://www.telize.com/geoip") | |
let urlRequest = NSURLRequest(URL: url) | |
let session = NSURLSession.sharedSession() | |
let task = session.dataTaskWithURL(url, | |
completionHandler: {data, response, error -> Void in | |
if error != nil { | |
println("error") | |
} else { | |
let result = NSJSONSerialization.JSONObjectWithData(data, options: | |
NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary | |
println(result); | |
} | |
}) | |
task.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment