← All courses

Lists, ForEach & Navigation

🗓 May 31, 2026 ⏱ 1 min read

List and ForEach

struct User: Identifiable { let id = UUID(); let name: String }

struct UsersView: View {
    let users = [User(name: "Anand"), User(name: "Priya")]
    var body: some View {
        List(users) { user in
            Text(user.name)
        }
    }
}

NavigationStack

NavigationStack {
    List(users) { user in
        NavigationLink(user.name) {
            ProfileView(user: user)   // destination
        }
    }
    .navigationTitle("Users")
}

Swipe actions & sections

List {
    Section("Team") {
        ForEach(users) { u in Text(u.name) }
            .onDelete { indexSet in /* remove */ }
    }
}
Tip: Items must be Identifiable (or pass id:) so SwiftUI can track and animate them.