-
-
Save austinmurtha/09ff3947a3f8417d821d 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() -> Double { | |
//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 | |
println("MultiplerRate \(multiplierRate)") | |
return multiplierRate | |
}) | |
} | |
} | |
} | |
}) | |
downloadTask.resume() | |
//return multiplierRate | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment