0

I've tried to look at other answers with this same problem but I still can not fix this. Please help me with this code which is for a weather app. The problem is on my let task = sessionDataTask line.

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()
    }
}
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
Step Step
  • 97
  • 1
  • 12

1 Answers1

2

Change your

let url = NSURL(string: path)

to

let url = URL(string: path)

That will fix your code

haider_kazal
  • 3,448
  • 2
  • 20
  • 42
  • As a rule of thumb for swift >2.x: remove NS everywhere (apart fro some particular case for example NSString..)ou can fall in strange errors, for example: – ingconti Jan 17 '18 at 21:35