Lets say I have two Object subclasses:
class Person: Object {
@Persisted var name: String
@Persisted var pets: List<Pet>
}
class Pet: Object {
@Peristed var name: String
@Peristed var numLegs: Int
@Persisted var owner: LinkingObjects<Person>
}
and I have a screen in my app that needs to show a list of all pets where each cell shows:
- the pets
name
andnumLegs
- the owners name (
owner.first!.name
).
I’m uncertain how I could update the UI of my app when the owners name changes.
I can easily update the UI when any of pets properties change by doing either of these:
realm.objects(Pet.self).observe { result in
switch result {
case .initial(let collection):
// store `collection` somewhere
case .update(let collection, let deletions, let insertions, let modifications):
// update UI
case .error(let error):
// handle error
}
}
or
realm.objects(TaskCompletion.self)
.collectionPublisher()
.subscribe(on: DispatchQueue(label: "<some label>"))
.receive(on: DispatchQueue.main)
.assertNoFailure()
.assign(to: \.completionGroups, on: self)
Assuming I save a reference to them, both of these will fire when a new pet was added, removed or was in someway modified.
however, neither of these fire when any of the pet’s owner’s properties change.
Does anyone have any advice for I could be notified when a property of a pet’s owner is changed?