简体   繁体   English

在 'StringProtocol' 上引用运算符 function '!=' 需要 'Binding<string> '符合'StringProtocol' swiftui</string>

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

I am new to swiftui and learning it.我是 swiftui 的新手,正在学习它。

I have a situation where I have to Compare Binding with String.我有一种情况,我必须将 Binding 与 String 进行比较。 I can't post a working code because it is very lengthy although I have posted a Statement where I am getting error.我无法发布工作代码,因为它非常冗长,尽管我已经发布了一个出现错误的声明。

I have to compare Binding with String in order to show and hide few fields based on the comparison.我必须将 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

Please help me to achieve this.请帮助我实现这一目标。

you only need the "$" dollar sign if you want to use the binding value, it means you want to change the value of it.如果你想使用绑定值,你只需要“$”美元符号,这意味着你想改变它的值。 In your case just use the the variable without the $.在您的情况下,只需使用不带 $ 的变量。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 参数类型“字符串?” 不符合预期的类型“StringProtocol” - Argument type 'String?' does not conform to expected type 'StringProtocol' 解码 SwiftUI 中的 Wordpress API 值时的 StringProtocol 问题 - StringProtocol issue when decoding Wordpress API value in SwiftUI 运算符 function '==' 要求 'Entry' 符合 'Equatable' - Operator function '==' requires that 'Entry' conform to 'Equatable' 如何让绑定值符合SwiftUI中的Equatable - How to make a binding value conform to Equatable in SwiftUI ForEach 要求 '[String: String]' 符合 'Identifiable' - ForEach requires that '[String : String]' conform to 'Identifiable' 在 'ForEach' 上引用初始化程序 'init(_:content:)' 要求 'Pl.net' 符合 'Identifiable' - Referencing initializer 'init(_:content:)' on 'ForEach' requires that 'Planet' conform to 'Identifiable' 实例方法“flatMap”要求“String”符合“ObservableConvertibleType” - Instance method 'flatMap' requires that 'String' conform to 'ObservableConvertibleType' SwiftUI - 错误 - 初始化程序 &#39;init(_:rowContent:)&#39; 要求 &#39;CustomDataModel&#39; 符合 &#39;Identifiable&#39; - SwiftUI - Error - Initializer 'init(_:rowContent:)' requires that 'CustomDataModel' conform to 'Identifiable' SwiftUI 字符串符合 Identifiable 似乎不正确 - SwiftUI String conform Identifiable seems not correct 下标 'subscript(_:)' 要求 'String.Index' 符合 'RangeExpression' - Subscript 'subscript(_:)' requires that 'String.Index' conform to 'RangeExpression'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM