Optionals vs Result
Here’s the code if you want to experiment with it!
import Foundation
func fetchData(_ completion: @escaping (Result<Data, Error>) -> Void) {
/* ... */
}
fetchData { result in
switch result {
case .success(let data):
// use the data
case .failure(let error):
// handle the error
}
}