List
Part of the Introduction to SwiftUI section of Coddy's Swift journey. Lesson 31 of 50.
List shows rows in the scrolling, grouped style of the Settings app. It takes a collection and a closure for each row, like ForEach:
List(books) { book in
Text(book.title)
}A list can also have fixed rows, and Section groups rows under a header:
List {
Section("Reading") {
Text("Dune")
}
Section("Finished") {
ForEach(finished, id: \.self) { title in
Text(title)
}
}
}Each row can hold any view: an HStack with an icon, text and a Spacer is a typical row.
Challenge
EasyShow the playlist as a List: one row per song, with the identifier songs on the list. Each row is an HStack with the music.note symbol and the song's name.
Try it yourself
import SwiftUI
@main
struct CoddyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Introduction to SwiftUI
Practice on your own: Swift playground