I have two classes nested in another class, which is an observable object in a SwiftUI view. Even though properties in the nested classes are declared as @Published, their value
You can expand upon the answer in the question you linked to by using CombineLatest to have your model fire its objectWillChange
publisher when either of the underlying objects change:
import Combine
class Model: ObservableObject {
@Published var submodel1: Submodel1 = Submodel1()
@Published var submodel2: Submodel2 = Submodel2()
var anyCancellable: AnyCancellable? = nil
init() {
anyCancellable = Publishers.CombineLatest(submodel1.$count,submodel2.$count).sink(receiveValue: {_ in
self.objectWillChange.send()
})
}
}