Skip to content

Instantly share code, notes, and snippets.

@alexnikol
Last active August 17, 2020 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexnikol/ad6071eb752511fbf9b63d72550a815d to your computer and use it in GitHub Desktop.
Save alexnikol/ad6071eb752511fbf9b63d72550a815d to your computer and use it in GitHub Desktop.
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