Scenario:
User selects a static item from a Picker which is stored into a $State variable.
Desired feature:
A function (e.g. doSomething( ) ) is fired EVERY TIME the Picker is used or whenever the $State variable has changed.
@State private var currentChoice = 0 {
didSet {
doSomething()
}
}
...
Picker("Weapon", selection: $currentChoice) {
ForEach(0 ..< moves.count) {
Text("\(self.moves[$0])")
}
}.pickerStyle(SegmentedPickerStyle())
Question: What's the correct declarative/SwiftUI/Combine paradigm to use?
Do I have to make Picker a publisher?
How is that done in this particular scenario?