30.3 Using OutlineGroup
Behind the scenes of the above example, the List view is making use of the OutlineGroup view. When used directly, OutlineGroup provides the same basic functionality such as automatically traversing the data tree structure and providing disclosure controls, but with greater control in terms of customizing the display of the data, particularly in terms of organizing data into groups.
Figure 30-4, for example, shows the same car data displayed using OutlineGroup within a List to categorize the data into sections titled Hybrid Cars and Electric cars:
Figure 30-4
The SwiftUI declaration to create and implement the above display using the same car data reads as follows:
struct ContentView: View {
var body: some View {
List {
ForEach(carItems) { carItem in
...