对成员' dataTask(with:completionHandler:)'的模糊引用swift 3.0

时间:2016-12-19 03:04:36

标签: swift swift3 nsurlsession

我试图用同样的问题查看其他答案,但我仍然无法解决这个问题。请帮我这个天气应用程序的代码。问题出在我的let task = sessionDataTask行。

import Foundation

protocol WeatherServiceDelegate {
    func setWeather(weather: Weather)
}
class WeatherService {
    var delegate: WeatherServiceDelegate?
    func getWeather(city: String)  {
        let path = "http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=79933f5c001b81aecc59976577f8134f"
        let url = NSURL(string: path)
        let session = URLSession.shared
        let task = session.dataTask(with: url) { (data, response, error) in
            print(data)
        }
        task.resume()
    }
}

1 个答案:

答案 0 :(得分:1)

更改您的

let url = NSURL(string: path)

let url = URL(string: path)

这将修复你的代码