Building Models.swift

One struct per JSON shape

Models/Models.swift is the whole API contract, translated into Swift: one struct (or enum) for every JSON shape in docs/API-CONTRACT.md. In this lesson you'll build the core four: User, AuthResponse, Booking, and Pet.

Two freebie protocols

You'll see two new conformances next to Codable:

  • Identifiable β€” a protocol with one requirement: an id property. SwiftUI lists demand it so they can tell rows apart (which row moved, which got deleted). Our structs already have id, so conforming costs zero extra code.
  • Hashable β€” the value can be boiled down to a number (a hash), which lets it live in a Set (Swift's no-duplicates collection) and β€” the reason we care β€” be used for screen-to-screen navigation later. The compiler synthesizes it for free when every property is itself Hashable.

That's the pattern all over this file: declare the conformance, pay nothing.