Handling URLSession Errors Safely
Spot the bug in this URLSession data task that mishandles flaky connectivity and errors.
Codeswift
func loadProfile(completion: @escaping (Profile?) -> Void) {
isLoading = true
let task = URLSession.shared.dataTask(with: url) { data, response, error in
self.isLoading = false
let profile = try? JSONDecoder().decode(Profile.self, from: data!)
completion(profile)
}
task.resume()
}What is the bug in this networking code?