Last active
August 17, 2020 07:42
-
-
Save alexnikol/ad6071eb752511fbf9b63d72550a815d to your computer and use it in GitHub Desktop.
Problematic code before the Generics magic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PetNetworkManager | |
func handleDecoding(responseData: Data, | |
completion: @escaping (_ apiResponse: Pet?, _ error: String?) -> Void) { | |
do { | |
let apiResponse = try JSONDecoder().decode(Pet.self, from: responseData) | |
completion(apiResponse, nil) | |
} catch { | |
completion(nil, "Network Error") | |
} | |
} | |
// UserNetworkManager | |
func handleDecoding(responseData: Data, | |
completion: @escaping (_ apiResponse: User?, _ error: String?) -> Void) { | |
do { | |
let apiResponse = try JSONDecoder().decode(User.self, from: responseData) | |
completion(apiResponse, nil) | |
} catch { | |
completion(nil, "Network Error") | |
} | |
} | |
// VetNetworkManager | |
func handleDecoding(responseData: Data, | |
completion: @escaping (_ apiResponse: Vet?, _ error: String?) -> Void) { | |
do { | |
let apiResponse = try JSONDecoder().decode(Vet.self, from: responseData) | |
completion(apiResponse, nil) | |
} catch { | |
completion(nil, "Network Error") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment