Skip to content

Instantly share code, notes, and snippets.

@eblaauw
Created March 31, 2015 15:44
Show Gist options
  • Save eblaauw/275eeaab9038a2f3f3da to your computer and use it in GitHub Desktop.
Save eblaauw/275eeaab9038a2f3f3da to your computer and use it in GitHub Desktop.
Swift
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let urlPath = "http://telize.com/geoip"
let url = NSURL(string: urlPath)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url!, completionHandler: {data, response, error -> Void in
if (error != nil) {
println(error)
} else {
let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
println(jsonResult["postal_code"])
}
})
task.resume()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment