7

It easy to create a simple list like this:

List { Text("Item 1") Text("Item 2") Text("Item3") }

But how I can add a selection like traditional NSTable?

malhal
  • 26,330
  • 7
  • 115
  • 133
Nayef
  • 463
  • 5
  • 13
  • Do you mean selection like https://stackoverflow.com/questions/56706188/how-does-one-enable-selections-in-swiftuis-list?noredirect=1&lq=1? – Fabian Aug 19 '19 at 05:55
  • 1
    I meant the blue Highlight bar to chose specific row, I am workin on Mac OS App – Nayef Aug 19 '19 at 08:18
  • Thank you, the examples in that question helped me – Nayef Aug 19 '19 at 14:38

1 Answers1

9
struct names {
    var id = 0
    var name = ""
}

var demoData = ["Phil Swanson", "Karen Gibbons", "Grant Kilman", "Wanda Green"]

struct SelectionDemo : View {
    @State var selectKeeper = Set<String>()

    var body: some View {

        HStack {
            List(demoData, id: \.self, selection: $selectKeeper){ name in
                Text(name)
            }.frame(width: 500, height: 460)
        }
    }
}

#if DEBUG
    struct ContentView_Previews: PreviewProvider {
        static var previews: some View {
            SelectionDemo()
        }
    }
#endif
Nayef
  • 463
  • 5
  • 13