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
typealias JSONDictionary = [String : Any] | |
typealias JSONArray = [Any] | |
struct JSONCodingKeys: CodingKey { | |
var stringValue: String | |
init?(stringValue: String) { | |
self.stringValue = stringValue | |
} |
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
struct BasicModelSynthesized: Decodable { | |
let someProperty: String | |
} |
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
struct BasicModelCustom: Decodable { | |
let someProperty: String | |
enum Keys: CodingKey { | |
case someProperty | |
} | |
init(from decoder: Decoder) throws { | |
let container = try decoder.container(keyedBy: Keys.self) | |
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
{ | |
"someProperty": "text" | |
} |
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
{ | |
"someProperty": null | |
} |
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
struct BasicModelOptionalSynthesized: Decodable { | |
let someProperty: String? | |
} |
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
struct BasicModelOptionalCustom: Decodable { | |
let someProperty: String? | |
enum Keys: CodingKey { | |
case someProperty | |
} | |
init(from decoder: Decoder) throws { | |
let container = try decoder.container(keyedBy: Keys.self) | |
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
struct BasicModelIfPresent: Decodable { | |
let someProperty: String? | |
enum Keys: CodingKey { | |
case someProperty | |
} | |
init(from decoder: Decoder) throws { | |
let container = try decoder.container(keyedBy: Keys.self) | |
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
Decoding method | Value exists | Null | Attribute missing | |
---|---|---|---|---|
synthesized String property | ✅ | ❌ | ❌ | |
decode(String, ...) | ✅ | ❌ | ❌ | |
synthesized String? property | ✅ | ✅ | ✅ | |
decode(String?, ...) | ✅ | ✅ | ❌ | |
decodeIfPresent(String, ...) | ✅ | ✅ | ✅ |
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
{ | |
"array": [ | |
1, | |
2, | |
3 | |
] | |
} |
OlderNewer