@MainActor
final class VM : ObservableObject {
@Published var secondClass: secondClass
@Published var counter: Int = 0
init(secondClass: secondClass) {
self.secondClass = secondClass
}
}
class secondClass: ObservableObject {
@Published var number : Int = 0
@Published var users : [DBUser]
@Published var userCount : Int
init(users: [DBUser], userCount: Int) {
self.users = users
self.userCount = userCount
}
}
struct test2: View {
@ObservedObject var VM : VM
var body: some View {
VStack{
Text("\(VM.secondClass.userCount)")
Button {
DispatchQueue.main.async {
VM.secondClass.userCount = 1
//VM.counter += 1
}
} label: {
Text("Click Here")
}
}
}
}
I have a nested class inside my ViewModel but when I update the classes attributes it doesn't cause the publisher to fire, whereas if I update a value directly attached to the ViewModel it does fire. How do I make the publisher fire when I update one of the nested classes attributes? Thanks