jsondecoder

Solutions on MaxInterview for jsondecoder by the best coders in the world

showing results for - "jsondecoder"
Dario
30 May 2020
1struct GroceryProduct: Codable {
2    var name: String
3    var points: Int
4    var description: String?
5}
6
7let json = """
8{
9    "name": "Durian",
10    "points": 600,
11    "description": "A fruit with a distinctive scent."
12}
13""".data(using: .utf8)!
14
15let decoder = JSONDecoder()
16let product = try decoder.decode(GroceryProduct.self, from: json)
17
18print(product.name) // Prints "Durian"
19