MΓ³dulo 03 Β· Swift for Real Apps: Codable & Async β LecciΓ³n 3 de 4 Β· ~15 min
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: anidproperty. SwiftUI lists demand it so they can tell rows apart (which row moved, which got deleted). Our structs already haveid, so conforming costs zero extra code.Hashableβ the value can be boiled down to a number (a hash), which lets it live in aSet(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.