Slide 12
Slide 12 text
従来の非同期処理の例
func downloadData(from url: URL, completion: @escaping (Result) -> Void) {
URLSession.shared.dataTask(with: url) { data, response, error in
if let error = error {
completion(.failure(error))
return
}
if let response = response as? HTTPURLResponse {
guard response.statusCode == 200 else {
completion(.failure(ResponseError(statusCode: response.statusCode)))
return
}
}
completion(.success(data!))
}.resume()
}