2014-10-22 1 views
1

Вот мой код: println (currentWeatherDictionary) должен распечатать погоду для этих координат с этого URL-адреса, но он ничего не распечатывает, это проблема с xcode? Им с помощью Xcode 6,01println (currentWeatherDictionary) функция не работает

import UIKit 

class ViewController: UIViewController { 

    //Replace the string below with your API Key. 
    private let apiKey = "d22b3b492d25282da275e826cc50757b" 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 

     let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/") 
     let forecastURL = NSURL(string: "43.067827,-77.541085", relativeToURL: baseURL) 


     let sharedSession = NSURLSession.sharedSession() 
     let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL!, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in 

      if (error == nil) { 
       let dataObject = NSData(contentsOfURL: location) 
       let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary 


       let currentWeatherDictionary: NSDictionary = weatherDictionary["currently"] as NSDictionary 

       println(currentWeatherDictionary) 

      } 

     }) 

     downloadTask.resume() 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 


} 

ответ

0

Это не представляется возможным для println(currentWeatherDictionary) линии должны быть выполнены, и ничего не печатать. Убедитесь, что error не nil и что обработчик завершения вызова. Вы можете сделать это с помощью либо контрольных точек, либо дополнительных println операторов.

Смежные вопросы