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 Vehicles: Codable { | |
let vehicles: [Vehicle] | |
} | |
struct Vehicle: Codable { | |
let name: String | |
let travelsOn: Medium | |
let numberOfWheels: Int | |
} |
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
{ | |
"vehicles": [{ | |
"name": "car", | |
"travels-on": "road", | |
"number-of-wheels": 4 | |
}, { | |
"name": "boat", | |
"travels-on": "water", | |
"number-of-wheels": 0 | |
}, { |
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
let jsonData = try Data(contentsOf: jsonResourceURL) | |
let decoder = JSONDecoder() | |
let vehicles try decoder.decode(Vehicles.self, from: jsonData) |
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 Vehicles: Codable { | |
let vehicles: [Vehicle] | |
} | |
struct Vehicle: Codable { | |
let name: String | |
let travelsOn: Medium | |
let numberOfWheels: Int | |
enum CodingKeys: String, CodingKey { |
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
{ | |
"vehicles": [{ | |
"name": "car", | |
"travels_on": "road", | |
"number_of_wheels": 4 | |
}, { | |
"name": "boat", | |
"travels_on": "water", | |
"number_of_wheels": 0 | |
}, { |
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
let jsonData = try Data(contentsOf: jsonResourceURL) | |
let decoder = JSONDecoder() | |
decoder.keyDecodingStrategy = .convertFromSnakeCase | |
let vehicles try decoder.decode(Vehicles.self, from: jsonData) |
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 AnyKey: CodingKey { | |
static let empty = AnyKey(string: "") | |
var stringValue: String | |
var intValue: Int? | |
init?(stringValue: String) { | |
self.stringValue = stringValue | |
self.intValue = nil |
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
let jsonData = try Data(contentsOf: jsonResourceURL) | |
let decoder = JSONDecoder() | |
decoder.keyDecodingStrategy = .convertFromKebabCase | |
let vehicles try decoder.decode(Vehicles.self, from: jsonData) |
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 Vehicles: Codable { | |
let VEHICLES: [Vehicle] | |
} | |
struct Vehicle: Codable { | |
let NAME: String | |
let TRAVELS_ON: Medium | |
let NUMBER_OF_WHEELS: Int | |
} |
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
let jsonData = try Data(contentsOf: jsonResourceURL) | |
let decoder = JSONDecoder() | |
decoder.keyDecodingStrategy = .letterCaseStrategy(from: .kebab, to: .macro) | |
let vehicles try decoder.decode(Vehicles.self, from: jsonData) |
OlderNewer