Last active
May 29, 2019 13:56
-
-
Save elenipapanik/86573e4d05c7d05172db051a30a16cc6 to your computer and use it in GitHub Desktop.
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
// For models that are ALREADY Swift.Decodable and want to be used inside Argo decodable models | |
protocol SwiftToArgoDecodable: Argo.Decodable, Swift.Decodable where Self.DecodedType == Self {} | |
extension SwiftToArgoDecodable { | |
static func decode(_ json: JSON) -> Decoded<DecodedType> { | |
do { | |
let jsonData = try JSONSerialization.data(withJSONObject: json.JSONObject(), options: []) | |
let decodedValue = try JSONDecoder().decode(Self.self, from: jsonData) | |
return .success(decodedValue) | |
} catch let error { | |
return .failure(.custom((error as NSError).description)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment