Home > front end >  Referencing operator function '!=' on 'StringProtocol' requires that 'Bindi
Referencing operator function '!=' on 'StringProtocol' requires that 'Bindi

Time:10-04

I am new to swiftui and learning it.

I have a situation where I have to Compare Binding with 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.

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.

CodePudding user response:

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()
}
  • Related