Skip to content

Instantly share code, notes, and snippets.

@toast38coza
Created October 19, 2014 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toast38coza/eb8da7d90aab94f44a3c to your computer and use it in GitHub Desktop.
Save toast38coza/eb8da7d90aab94f44a3c to your computer and use it in GitHub Desktop.
Call a JSON endpoint with swift
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