【发布时间】:2015-12-27 05:17:00
【问题描述】:
do catch 不工作,这是错误:
从'(NSURL?, NSURLResponse?, NSError?) throws -> Void' 类型的抛出函数到非抛出函数类型'(NSURL?, NSURLResponse?, NSError?) -> Void'的无效转换
这是代码:
let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL!, completionHandler: { (location: NSURL?, response: NSURLResponse?, error: NSError?) -> Void in
如果有帮助,这就是全部代码:
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 = try NSJSONSerialization.JSONObjectWithData(dataObject, options: nil, error: NSError?) as! NSDictionary
let currentWeather = Weather(weatherDictionary: weatherDictionary)
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.currentTemperature.text = "\(currentWeather.temperature)"
self.iconView.image = currentWeather.icon!
let formatter = NSDateFormatter()
formatter.timeStyle = .ShortStyle
self.currentTime.text = formatter.stringFromDate(NSDate())
self.humidity.text = "\(Int(currentWeather.humidity * 100))%"
self.rain.text = "\(Int(currentWeather.precipProbability))%"
self.summary.text = "\(currentWeather.summary)"
self.refreshActivityIndicator.stopAnimating()
self.refreshActivityIndicator.hidden = true
self.refreshButton.hidden = false
})
【问题讨论】:
-
你找到解决这个问题的方法了吗?任何帮助将不胜感激,因为我遇到了完全相同的问题。
标签: swift2 nsurl nsurlsession