Skip to content

Instantly share code, notes, and snippets.

@alexnikol

alexnikol/.swift

Created Aug 17, 2020
Embed
What would you like to do?
Generic way code after refactoring
func handleDecoding<Element: Decodable>(responseData: Data,
responseType: Element.Type,
completion: @escaping (_ apiResponse: Element?, _ error: String?) -> Void) {
do {
let apiResponse = try JSONDecoder().decode(responseType, 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.