Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //It is generally nicest to make the variables in your codable types optional, so your decoding can still succeed
- // even if the JSON is missing 1 or more fields
- struct MyCodableType: Codable {
- var myVar1: String?
- var myVar2: [Bool]?
- var myVar3: SomeOtherCodableType?
- //A CodingKeys enum is required if your variable names don't match the JSON names, case-sensitive.
- // The cases here should match your clientside variable names, and the associated values should match the JSON
- enum CodingKeys: String, CodingKey {
- case myVar1 = "JSONThing"
- case myVar2 = "OtherJSONThing"
- case myVar4 = "YetAnother"
- }
- }
- struct SomeOtherCodableType: Codable {
- var bestFood: String?
- }
Add Comment
Please, Sign In to add comment