๐Ÿ”ธdata model

terms โŸฉ data model

To share the same data between multiple views, you need a single source of truth that is separate from the views. This is the data model, and you can share it with any views that need access to the data.

import SwiftUI

// โญ๏ธ 1. define an observable object
class CreatureZoo : ObservableObject {
    // โญ๏ธ 2. publish its properties
    @Published var creatures = [
        Creature(name: "Gorilla", emoji: "๐Ÿฆ"),
        Creature(name: "Peacock", emoji: "๐Ÿฆš"),
    ]
}

struct Creature : Identifiable { ... }

Last updated