-
-
Save austinmurtha/6d27fa817fc387316116 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 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