How to use outline in the list?

I tried to replicate the code but I am not able to traverse the my data.

Code Block
import SwiftUI
struct ContentView: View {
  let testData: [Data]
  var body: some View {
    List(testData, children: \.children) { value in
      Text(value.values)
    }
  }
}
struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
    ContentView(testData: testData)
  }
}
let testData = [Data(), Data()]
struct Data: Identifiable {
  let id = UUID()
  let values: [String] = ["One", "Two", "Three"]
}

I am getting error "Value of type 'Data' has no member 'children'" . I even tried values instead of children but I am getting "Key path value type '[String]' cannot be converted to contextual type '[Data]?'"
Please let me know how to use \.children and outline group.
You need to have a data structure that has a property children on it - your current example has the properties id and values. Since the List with the children parameter is meant to show a hierarchy, the SwiftUI framework uses the property that you provide to that parameter (a keypath to the property .children in the example above) to look up that data relationship to display it.

Since you've provided a keypath that doesn't exist on that object, the compiler is letting you know that \.children isn't going to work.
First avoid using Data as this type already exists.

Second, like @heckj already described, you need to have a data structure that has a property children. Which holds an (optional) array of the same type.

I rewrote your code to show a working version:

Code Block
struct ContentView: View {
  let testData = [
    SomeData(name: "Parent One", children: [
      SomeData(name: "Child One", children: nil),
      SomeData(name: "Child Two", children: nil),
      SomeData(name: "Child Three", children: nil),
    ]),
    SomeData(name: "Parent Two", children: nil)
  ]
  var body: some View {
    List(testData, children: \.children) { data in
      Text(data.name)
    }
  }
}
struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
    ContentView()
  }
}
struct SomeData: Identifiable {
  var id: String = UUID().uuidString
  var name: String
  let children: [SomeData]?
}

Thank you @crystalminds for the working example. It helps a lot.
How to use outline in the list?
 
 
Q