I have a list View that takes a Binding to a selection.
struct SomeList: View {
@Binding var selection: SomeType?
var body: some View {
Button("Selected") {
selection = SomeType()
}
}
}
On the other side I like to know when a selection is made so I can do something with the result.
struct MainView: View {
@State private var showSomeList: Bool = false
@State private var someListSelection: SomeType?
var body: some View {
Button("Show Sheet") {
showSomeList = true
}
.sheet(isPresented: $showSomeList) {
SomeList(selection: $someListSelection)
}
.onChange(of: someListSelection) { //ERROR! NO OPTIONAL ALLOWED
//Do something with the some list selection.
}
}
}
How can I react on the selection?