我在下面的代码中得到一个表达式类型 'Binding<_>' 是模棱两可的,没有更多的上下文错误$order.quantity.contracts
:
struct ContractsPickerView: View {
@Binding var order: Order
var question: String
var body: some View {
Error
|
|
V
Picker(selection: $order.quantity.contracts, label: Text("\(question)").font(.headline)) {
ForEach(0..<101, id: \.self) { contracts in
Text("\(contracts)")
}
}
}
}
事实上,Xcode 并没有在键入后提供类contracts
中的属性。以下是模型:Quantity
$order.quantity.
struct Order {
var quantity: Quantity?
}
struct Quantity: Hashable {
private var userEnteredContracts: Int?
var contracts: Int {
get {
return userEnteredContracts
}
set(newContracts) {
userEnteredContracts = newContracts
}
}
}
有人可以解释这个问题并提供解决方案吗?