我正在尝试从该位置获取天气。位置正确获取但未获得天气信息。请帮我解决此问题
getWeatherData("api.openweathermap.org/data/2.5/weather?q=\(city)")
func getWeatherData (urlString:String)
{
let url = NSURL(string: urlString)
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data,response,error) in
dispatch_async(dispatch_get_main_queue()) {
self.setWeatherData(data!)
}
}
}
func setWeatherData(weatherData:NSData)
{
let json = try! NSJSONSerialization.JSONObjectWithData(weatherData, options: []) as! NSDictionary
if let main = json["main"] as? NSDictionary{
if let temp = main["temp"] as? Double{
weather = String(format: "%.1f", temp)
}
}
}