I tried to replicate the code as shown in Stacks, Grids, and Outlines in SwiftUI (12:35).
They make it feel like it's a very easy thing to do. Just insert a Section and as you could see in the video it will immediately become a collapsable view. Add a header to the section and it will get the bolder text style. I wasn't able to replicate this.
xCode Version 12.0 beta (12A6159)
Below you can find the code I used.
The expected result would be nicely styled, collapsable section headers.
The actual result is a non-collapsable section with a weird underline under the name and no arrow.
It uses this simple model to hold the canvases and graphics:
They make it feel like it's a very easy thing to do. Just insert a Section and as you could see in the video it will immediately become a collapsable view. Add a header to the section and it will get the bolder text style. I wasn't able to replicate this.
xCode Version 12.0 beta (12A6159)
Below you can find the code I used.
The expected result would be nicely styled, collapsable section headers.
The actual result is a non-collapsable section with a weird underline under the name and no arrow.
Code Block struct ContentView: View { let model: Model = Model() @State private var selection: Set<String> = [] var body: some View { NavigationView { List(selection: $selection) { ForEach(model.canvases) { canvas in Section(header: Text(canvas.name)) { OutlineGroup(canvas.graphics, children: \.children) { graphic in Label(graphic.name, systemImage: graphic.icon) } } } } .listStyle(SidebarListStyle()) .navigationTitle("Graphics") } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
It uses this simple model to hold the canvases and graphics:
Code Block struct Model: Identifiable { let id: String = UUID().uuidString let canvases: [Canvas] = [ Canvas(name: "Main", graphics: [ Graphic(name: "Rectangle", icon: "rectangle.fill"), Graphic(name: "Oval", icon: "circle.fill"), Graphic(name: "Group", icon: "rectangle.3.offgrid", children: [ Graphic(name: "Rectangle", icon: "rectangle.fill"), Graphic(name: "Rectangle", icon: "rectangle.fill"), Graphic(name: "Rectangle", icon: "rectangle.fill") ]), Graphic(name: "Group", icon: "rectangle.3.offgrid", children: [ Graphic(name: "Rectangle", icon: "rectangle.fill"), Graphic(name: "Rectangle", icon: "rectangle.fill"), Graphic(name: "Rectangle", icon: "rectangle.fill") ]) ]), Canvas(name: "Highlights", graphics: [ Graphic(name: "Triangle", icon: "triangle.fill"), Graphic(name: "Triangle", icon: "triangle.fill") ]), Canvas(name: "Version 2", graphics: [ Graphic(name: "Rectangle", icon: "triangle.fill"), Graphic(name: "Oval", icon: "circle.fill"), Graphic(name: "Triangle", icon: "triangle.fill") ]), ] } struct Canvas: Identifiable { var id: String = UUID().uuidString var name: String let graphics: [Graphic] } struct Graphic: Identifiable { var id: String = UUID().uuidString var name: String var icon: String var children: [Graphic]? }