I want to change some other unrelated @State variable when a Picker gets changed but there is no onChanged and it\'s not possible to p
Use onReceive and Just:
import Combine
import SwiftUI
struct ContentView: View {
@State private var selection = 0
var body: some View {
Picker("Some Label", selection: $selection) {
ForEach(0 ..< 5, id: \.self) {
Text("Number \($0)")
}
}
.onReceive(Just(selection)) {
print("Selected: \($0)")
}
}
}