I'm currently working on an app which has a number of different data objects with relationships between them.
For example, there is a Building
struct:
struct Building {
let id: UUID
var name: String
}
There is also an Address
struct, which has a Building
property:
struct Address: {
let id: UUID
var addressText: String
var building: Building
}
When I change the name of the Building
I would like it to update for all the corresponding Address
objects. Because structs are value types, this doesn't happen at present.
- I could fix this by changing
struct
toclass
, but because I'm working with SwiftUI that's not desirable. - I could fix this by updating the
Address
to store theid
of theBuilding
instead but having to look up the name of the corresponding building each time I want it feels messy to me.
Is there some other approach I'm missing? Or a recommended best practice way of handling relationships between structs?