SwiftUI Setting Bind<String> in Text field

I've got the following object that contain list of strings:

class handler: ObservableObject {
  @Published var items = [String]()
}

In some closure, I set this list with valid values :

for item in item_list! {
  self.handler.items.append(item.stringData)
}

and in the ContentView part I've got Picker that support to present that list of strings in realtime:

VStack {
  Picker("items", selection: $arg1) {
    ForEach($handler.items, id: \.self) {
      Text($0)
    }
  }
}

However, it fails to compile due to the following reason :

Initializer 'init(_:)' requires that 'Binding<String>' conform to 'StringProtocol'

Any Idea how to resolve this ?

1 Like

I just noticed that i forgot to remove the '$'. once removed, we don't get the Binding wrapper and the problem is resolved.

1 Like