Upgrade to Pro — share decks privately, control downloads, hide ads and more …

クリぼっちの自分が 信じられるのは もはや型のみである

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

クリぼっちの自分が 信じられるのは もはや型のみである

Avatar for Ryota Sakaguchi

Ryota Sakaguchi

December 25, 2018
Tweet

More Decks by Ryota Sakaguchi

Other Decks in Technology

Transcript

  1.          

                      
  2. { "shop": { "id": 1, "name": "", "employees": [ {

    "id": 1, "job_id": 1, "name": "kuluna" } ] } }
  3. import Foundation struct Employee: Decodable { let id: Int let

    job_id: Int let name: String } struct Shop: Decodable { let id: Int let name: String let employees: [Employee] } struct ShopResponse: Decodable { let shop: Shop }
  4. -

  5. !

  6. struct ShopId: Codable, Equatable { let value: Int init(_ value:

    Int) { self.value = value } public init(from decoder: Decoder) throws { self.value = try decoder.singleValueContainer().decode(Int.self) } public func encode(to encoder: Encoder) throws { var c = encoder.singleValueContainer() try c.encode(self.value) } }