Skip to content

Instantly share code, notes, and snippets.

@alexnikol

alexnikol/.swift

Last active Aug 17, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.