picker

Is there a way to call a function when a SwiftUI Picker selection changes an EnvironmentObject?

天大地大妈咪最大 提交于 2020-07-09 13:19:55
问题 I have a SwiftUI Form I'm working with, which updates values of an EnvironmentObject. I need to call a function when the value of a Picker changes, but every way I've found is either really messy, or causes other problems. What I'm looking for is a similar way in which the Slider works, but there doesn't seem to be one. Basic code without any solution is here: class ValueHolder : ObservableObject { @Published var sliderValue : Float = 0.5 static let segmentedControlValues : [String] = ["one",