Is there a way I can use .onChange to detect the change of multiple @State properties at once? I know I could just chain 2 .onChange modifiers but it would be better if I could just detect all at once and run some code.
@State private var width = 0.0
@State private var height = 0.0
var body: some View {
Button(action: {
width += 0.1
}, label: {
Text("Width + 0.1")
})
.onChange(of: width) { _ in
print("Changed")
}
}
>Solution :
For this case here is the simplest I think
.onChange(of: width + height) { _ in
print("Changed")
}