mattcomi on Nostr: #swiftui tip: If you want to fire an action when "foo” or "bar” changes, you can ...
#swiftui tip: If you want to fire an action when "foo” or "bar” changes, you can do this:
.onChange(of: foo) {
action()
}
.onChange(of: bar) {
action()
}
But you can't do this:
.onChange(of: foo || bar) {}
However, if foo and bar are the same type, you *can* do this:
.onChange(of: [foo, bar]) {}
This works because Array conforms to Equatable when its Element does.
.onChange(of: foo) {
action()
}
.onChange(of: bar) {
action()
}
But you can't do this:
.onChange(of: foo || bar) {}
However, if foo and bar are the same type, you *can* do this:
.onChange(of: [foo, bar]) {}
This works because Array conforms to Equatable when its Element does.