i had make a struct to pass the ObservedObject value change.
struct moveView : View {
@Binding var move : Bool
var body: some View {
if move{
return Text("1")
}else{
return Text("2")
}
}
}
struct TextView : View {
@ObservedObject var skc:xiangcene
var body: some View {
Text("test")
.opacity(moveView(move: $skc.move) == "1" ? 0.1 : 0.8) // it show
Referencing operator function '==' on 'StringProtocol' requires that 'moveView' conform to 'StringProtocol'
}
}
the compiler complaint “Referencing operator function '==' on 'StringProtocol' requires that 'moveView' conform to 'StringProtocol'” how can i fix that?
CodePudding user response:
Your struct is of type 'View' and you are comparing it to a 'String' constant.
You could check the boolean value:
.opacity(moveView(move: $skc.move).move ? 0.1 : 0.8)
But using a the expression:
moveView(move: $skc.move)
does not make sense here. You are creating a new view here with the value of the variable.
Better:
.opacity( skc.move ? 0.1 : 0.8)