SwiftUI List
Published Dec 14, 2022
Contribute to Docs
The List view arranges its elements into a column. It can be either static, when hard-coding the data into the list, or dynamic, when the data is pulled from an array.
Syntax
var body: some View {
List {
Subviews here
}
}
Example
In the example below, a List pulls the data from the continents array, and then displays them into a single column:
var continents = ["Africa", "Antartica", "Asia", "Europe", "North America", "Oceania", "South America"]var body: some View {List(continents, id: \.self) {Text($0)}}
id: \.selfallows Swift to identify each of the items uniquely in order to update the values when changed.$0is a shorthand syntax used to reference the first argument in a closure.
This will display the following:

Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SwiftUI on Codecademy
- Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.
- Includes 7 Courses
- With Certificate
- Beginner Friendly.13 hours
- A powerful programming language developed by Apple for iOS, macOS, and more.
- Beginner Friendly.12 hours