Picker
只有在与Int
一起使用时才能正常工作,当使用任何其他类型的BinaryInteger
时,它根本不会更新 Select .为了纠正这一点,我想做CompatilibityPicker
,但我必须承认,我对Binding
实际工作原理的理解给我带来了很多麻烦.以下是我当前的代码:
struct CompatibilityPicker<Label, SelectionValue, Content> : View where Label : View, SelectionValue : BinaryInteger, Content : View {
var content : () -> Content
var label : Label
@Binding var _selection : SelectionValue
var selection : Int {
get {
Int(_selection)
}
set {
self._selection = SelectionValue(newValue)
}
}
var body: some View {
// This line shows errors about selection and I don't know how to fix them,
// using $selection does not work either.
Picker(label, selection: selection, content: content)
}
}