I have a simple case as follows.
class Monster: ObservableObject {
static let shared = Monster()
@Published var selectionChanged = false
}
struct ContentView: View {
@ObservedObject var monster = Monster.shared
@State private var isOn = false
var body: some View {
VStack {
Button {
monster.selectionChanged.toggle()
} label: {
Text("Tap me")
}
.padding(.vertical, 60.0)
SecondView()
}
}
}
struct SecondView: View {
@StateObject var monster = Monster.shared
var body: some View {
VStack {
Text("Hello")
}.onChange(of: monster.selectionChanged) { _ in
print("GGGG")
}
}
}
So SecondView receives a call from Monster with through onChange.. Is there a simpler approach where SecondView receives a call without it? Thanks.