Created
July 13, 2017 15:30
-
-
Save Ravi61/2d8b4fd6f5c843e9afd361d12b93c548 to your computer and use it in GitHub Desktop.
Decoding Error Catch
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
//... | |
do { | |
let model = try jsonDecoder.decode(BattleShip.self, from: jsonData!) | |
print(model) | |
} catch DecodingError.dataCorrupted(let context) { | |
print(context.debugDescription) | |
} catch DecodingError.keyNotFound(let key, let context) { | |
print("\(key.stringValue) was not found, \(context.debugDescription)") | |
} catch DecodingError.typeMismatch(let type, let context) { | |
print("\(type) was expected, \(context.debugDescription)") | |
} catch DecodingError.valueNotFound(let type, let context) { | |
print("no value was found for \(type), \(context.debugDescription)") | |
} catch { | |
print("I know not this error") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Improved version to detected JSON keys order tree.
This will print JOSN tree for typeMismatch and valueNotFound: rootObject -> someKey / Index X -> faulty key