Slide 40
Slide 40 text
extension URLSession {
func dataTask(with url: URL, completionHandler: @escaping (Result) -> Void) -> URLSessionDataTask {
return dataTask(with: url) { (data, response, error) in
switch (data, error) {
case let (data?, nil):
completionHandler(Result.success(data))
case let (nil, error?):
completionHandler(Result.failure(error))
default: fatalError("Shouldn't come here ")
}
}
}
}