Skip to content

Instantly share code, notes, and snippets.

@austinmurtha
Created March 19, 2015 13:36
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 austinmurtha/6d27fa817fc387316116 to your computer and use it in GitHub Desktop.
Save austinmurtha/6d27fa817fc387316116 to your computer and use it in GitHub Desktop.
func getCurrencyData() {
//http://www.freecurrencyconverterapi.com/api/v3/convert?q=USD_PHP
let convertToRates = "convert?q=USD_EUR"
let baseURL = NSURL(string: "http://www.freecurrencyconverterapi.com/api/v3/")
let currencyURL = NSURL(string: "\(convertToRates)", relativeToURL: baseURL)
let sharedSession = NSURLSession.sharedSession()
println(sharedSession)
println(currencyURL)
let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(currencyURL!, completionHandler: { ( location: NSURL!, response:NSURLResponse!, error: NSError!) -> Void in
let dataObject = NSData(contentsOfURL: location!)
println(dataObject)
let currencyDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary
if let results = currencyDictionary["results"] as? NSDictionary {
println(results)
if let results2 = results["USD_EUR"] as? NSDictionary {
println(results2)
if let multiplierRate = results2["val"] as? Double{
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.exchangeRate = multiplierRate
println(self.exchangeRate)
})
}
}
}
})
downloadTask.resume()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment