I'm trying to migrate from Swift2 to Swift3 and I'm having an issue with URLSession.GET
I went through the migration tool provided by XCode, and changed my "NSURLSession" calls into "URLSession" but I keep having this error message:
"Use of Instance member 'GET' on type 'URLSession'; did you mean to use a value of type 'URLSession' instead?"
Here is my code:
open static func getData() -> Promise<[Station]> {
return URLSession.GET("http://api.xxx.gov/api/").asDataAndResponse().then { (data: NSData, _) -> [Station] in
var stations = [Station]()
// rest of the code to retrieve the data
...
...
return stations
}
}
Update: After some digging a found a solution, see answer below for more details and helpful links
After some more digging I found a solution :
First I have to init URLSession with a configuration:
let URLSession1 = URLSession(configuration: .default)
Then I can call the 'GET' method and I had to use
(data,_ )
instead of(data:NSData,_ )
:Some helpful StackOverflow links that helped me find the solution:
NSURLSession dataTaskForRequest:completion: unrecognized selector sent to instance