Created
August 17, 2020 07:39
-
-
Save alexnikol/de0b6518fa9feea26e9eba648386ae00 to your computer and use it in GitHub Desktop.
Generic way code after refactoring
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
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