thank you for answering.
This has been annoying me for days now and I've tried everything I can to fix it. For some reason the data parameter in this chunk of code:
let task = NSURLSession.sharedSession().dataTaskWithURL(url, completionHandler: {
(data, response, error) in
dispatch_async(dispatch_get_main_queue(), {
do {
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
if let main = json["main"] as? NSDictionary {
if let temp = main["temp"] as? Double {
self.temperature = String(format: "%.1f", temp);
print(self.temperature);
}
}
} catch (let error as NSError) {
print(error);
}
});
});
is ALWAYS nil. I've made sure the url is correct by copying and pasting it into safari, and when I go on the website, the data is on the page. Is there anything I have to fix?
Btw, here's the code that calls this part:
if (coordinate != nil) {
info.getWeatherData("http://ift.tt/2atUfGV, its a secret}");
print("api
Aucun commentaire:
Enregistrer un commentaire