Problematic code before the Generics magic
// 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