【发布时间】:2019-08-20 17:37:22
【问题描述】:
从 beta 5 开始,我的项目将不再编译。该按钮的文本错误为"Type of expression is ambiguous without more context"。
我认为它可能会在 beta 6 中修复,但事实并非如此。 macOS 也更新到 Catalina beta 7。
class ClPassport : ObservableObject , Identifiable {
@Published var mrz : String = "" //{ didSet { update() } }
var isValid : Bool {
return true
}
func update() {
objectWillChange.send(())
}
func getMRZKey() -> String {
return ""
}
}
struct ContentView : View {
@ObservedObject var passportDetails = ClPassport()
var body: some View {
ZStack{
VStack(alignment: .leading){
HStack{
Spacer()
Button(action: {
self.scanPassport( mrzKey: self.passportDetails.getMRZKey() )
}) {
Text("Read Chip") // <- "Type of expression is ambiguous without more context"
.font(.largeTitle)
.foregroundColor(passportDetails.isValid ? .primary : Color.secondary.opacity(0.25))
.padding()
}.padding()
.background(Color.white.opacity(passportDetails.isValid ? 1 : 0.5))
.cornerRadius(15)
.padding()
.disabled( !passportDetails.isValid )
Spacer()
}
TextField($passportDetails.mrz, placeholder: Text("MRZ"))
}
}
}
func scanPassport( mrzKey: String ) {
//do stuff with mrzKey
}
}
【问题讨论】:
-
这是否有可能在
ForEach中,它将 Binding作为闭包迭代类型?