I finally found a solution. It's amazing when we missed the forest behind the trees. There are two questions:
1) Swift 4 seems to have changed the signature dataTask(with: NSURLRequest)todataTask(with: URLRequest)
funct , dataTask URLSession, , . , NSURLRequest URLRequest .
2) , dataTask cast URLSessionDataTask, .
Swift 4:
typealias DataTaskResult = (Data?, URLResponse?, Error?) -> Void
protocol URLSessionProtocol {
func dataTask(with request: URLRequest, completionHandler: @escaping DataTaskResult) -> URLSessionDataTaskProtocol
}
extension URLSession: URLSessionProtocol {
func dataTask(with request: URLRequest, completionHandler: @escaping DataTaskResult) -> URLSessionDataTaskProtocol {
let task:URLSessionDataTask = dataTask(with: request, completionHandler: {
(data:Data?, response:URLResponse?, error:Error?) in completionHandler(data,response,error) }) as URLSessionDataTask
return task
}
}
, URLSession.shared , URLSession(), .