enum SectionType: String, CaseIterable {
case top = "Top"
case best = "Best"
}
struct ContentView : View {
@State private var selection: Int = 0
var body: some View {
SegmentedControl(selection: $selection) {
ForEach(SectionType.allCases.identified(by: \.self)) { type in
Text(type.rawValue).tag(type)
}
}
}
}
当 $selection
状态改变时,我如何运行代码(例如 print("Selection changed to \(selection)")
) ?我看了所有的文件,什么都没找到。