SwiftUI List: More Than Just a Table View

A SwiftUI List is a declarative container for scrollable rows of data, like a modern UITableView. Use it for settings, feeds, or contact lists. The footgun: never nest a List inside a ScrollView, as it breaks scrolling behavior.
WHY IT EXISTS To provide a simple, declarative way to display collections of data that automatically adapts its appearance to the platform (iOS, macOS, etc.) and handles performance optimizations like view recycling under the hood. It replaces the complex, delegate-and-datasource-based setup of UIKit's UITableView.
THE MENTAL MODEL Think of a List as a recipe for displaying data, not the final dish. You provide the data (an array of items) and a template for one row. SwiftUI then bakes the full, scrollable list for you, handling all the complex parts like cell reuse and platform-specific styling.
HOW IT WORKS A List takes a collection of data where each item is uniquely identifiable. For each item, it uses a view builder closure you provide to create a row. SwiftUI manages the underlying platform-specific components, reusing views for performance as you scroll. You can create static lists with explicit rows or, more commonly, dynamic lists from a data collection.
WHEN TO USE IT Use List for displaying data in a single, vertical column. It's perfect for settings screens, master-detail interfaces, feeds, and contact lists. Its built-in support for sections, headers, footers, and swipe actions makes it very powerful for standard UI patterns.
WHEN NOT TO USE IT Avoid List for highly custom, non-linear layouts like a grid or a staggered collection; use LazyVGrid or LazyHGrid for those. If you just need a few static items in a scrollable container, a ScrollView with a VStack is simpler and more direct. The primary footgun is nesting a List inside another scrolling view like ScrollView, which breaks scrolling behavior.
ONE CANONICAL EXAMPLE To display a list of users, you'd pass an array of User objects to the List initializer, where the User type is Identifiable. Inside the List's closure, you'd define what a single UserRowView looks like. SwiftUI then iterates over your users and creates a UserRowView for each one, arranging them in a scrollable, performant list.
Read the original → developer.apple.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.