我在 xcode beta 4 上使用 swiftUI,但看不到对象或属性是否相等。当我想将某事等同起来时,我会在同一行出现错误:“对成员 '==' 的不明确引用”。
这是我的代码,但在我的代码中的其他场合,我也不能等同于枚举等其他东西。这是我的错误还是错误?
struct PickerView: View {
@ObjectBinding var data: Model
// let selector: PickerType
let selector: String
let width: CGFloat
let height: CGFloat
var body: some View {
VStack {
if selector == "countdown" {
Picker(selection: $data.countDownTime, label: Text("select Time")) {
ForEach(1...240) { diget in
Text("\(diget)")
}
}
.frame(width: width, height: (height/2), alignment: .center)
} else {
Picker(selection: $data.exercise, label: Text("select Time")) {
ForEach(data.exercises) { exercise in
Text("\(exercise)")
}
}
.frame(width: width, height: (height/2), alignment: .center)
}
}
}
}
在 SwiftUI 视图中,错误有时可能会产生误导。它可能出现在代码的某一部分,但真正的原因可能是向上或向下几行代码。
在您的情况下,您输入了错误的视图名称:
PickerView(selection: $data.countDownTime, label: Text("select Time"))
当你真正的意思是:
Picker(selection: $data.countDownTime, label: Text("select Time"))
并且因为 PickerView 实际上确实存在,但是有不同的参数,所以你得到了一个非常具有误导性的错误。
当发生此类事情时,我建议您注释掉给您带来毫无意义的错误的代码,您会看到编译器会将您指向其他地方。希望是正确的地方。在您的情况下,如果您暂时更改: if selector == "countdown"
by if true
,编译器会为您指明正确的方向。试试看,你会明白我的意思。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句