在 'StringProtocol' 上引用运算符函数 '!=' 要求 'Binding<String>' 符合 'StringProtocol' swiftui

Referencing operator function '!=' on 'StringProtocol' requires that 'Binding<String>' conform to 'StringProtocol' swiftui

我是 swiftui 的新手,正在学习它。

我有一种情况需要比较 Binding 和 String。我无法 post 一个工作代码,因为它非常冗长,尽管我已经 post 编辑了一个出现错误的声明。

我必须将 Binding 与 String 进行比较,以便根据比较显示和隐藏几个字段。

if $viewModel.users[indexValue].relationshipLabel != "Choose" {
     ShowView()
    } else {
    HideView()
    }




Getting error "**Referencing operator function '!=' on 'StringProtocol' requires that 'Binding<String>' conform to 'StringProtocol'**" on line first Statement

请帮我实现这个。

如果你想使用绑定值,你只需要“$”美元符号,这意味着你想改变它的值。在您的情况下,只需使用不带 $.

的变量
if viewModel.users[indexValue].relationshipLabel != "Choose" {
 ShowView()
} else {
HideView()
}