Neil Macy

List Sections in SwiftUI

I'm aware that I'm very late to this party. But this is still really cool.

In SwiftUI, if you want to create a table view (which is actually called a List, in SwiftUI terminology) section, you can just pass in a view for the header and footer, and list the views that should be inside it. In UIKit, this is multiple lines of calls to the UITableViewDelegate. In SwiftUI, it's all just a handful of lines of code!

List {
	Section(header: Text("My Section").bold(), footer: Text("Footer information about my section")) {
		Text("Row 1")
		Text("Row 2")
		Text("Row 3")
	}
}

Published on 22 April 2022