0

Im trying to update my basic weather app i made with swift 2 to swift 3 this is my code:

func getWeather(city: String) {

    let path = "http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=095711373620570aa92ee530246dc8af"
    let url = NSURL(string: path)
    let session = NSURLSession.sharedSession()
    let task = session.dataTaskWithURL(url!) { (data: NSData?, response: NSURLResponse?, error: NSError?) -> Void in
        print(">>>> \(data)")
    }

and NSURLSession.sharedSession(5th line) and NSURLResponse(6th line) print out an error

2 Answers2

6

Don't annotate types in the completion handler signature and use the Swift 3 native structures:

func getWeather(city: String) {

    let path = "http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=095711373620570aa92ee530246dc8af"
    let url = URL(string: path)
    let session = URLSession.shared
    let task = session.dataTask(with:url!) { (data, response, error) -> Void in
        print(">>>> \(data)")
    }
vadian
  • 274,689
  • 30
  • 353
  • 361
0

Swift 3 update

URLSession.shared.dataTask()

  • 1
    Any chance you could explain your answer a bit more in detail? Please see [how to answer](https://stackoverflow.com/help/how-to-answer) – Icepickle Jun 29 '17 at 21:46