Is there a way to access the $
implicit write with embedded objects?
For instance, this doesn’t work because an embedded object has to be marked as optional:
class Location: Object, ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var _id: = UUID()
@Persisted var name: String = ""
@Persisted var address: Address?
}
class Address: EmbeddedObject {
@Persisted var address1: String = ""
@Persisted var city: String = ""
@Persisted var state: String = ""
@Persisted var zip: String = ""
}
TextField("Business name...", text: $business.name)
TextField("Address...", text: $location.address.address1)
TextField("City...", text: $location.address.city)
TextField("State...", text: $location.address.state)
TextField("Stage Zip Code...", text: $location.address.zip)
If I try to change the address to non-optional, that throws an error.
And I can’t find a way or an example on how to implicitly write these which makes me do a complicated dance where I load existing values into state variables and save on dismissal, which may never happen.
Any best practices here?