List and ForEachThese are the lesson notes for this day. Its build-along tutorial and flash cards have not been written yet.
List and ForEachList shows scrolling rows with the system's styling, swipe actions, selection, and sections. It reuses rows for performance, as UITableView does. ForEach produces views from a collection, and can be used inside a List or inside any other container. Both need a stable, unique identity for every element: either make your type conform to Identifiable, or pass an id: key path. Using array indices, or \.self on values that are not unique, leads to wrong animations, lost state, and crashes when a row is deleted.
The everyday tools: .swipeActions for row actions, .onDelete and .onMove for editing, Section for grouping, and .listStyle for appearance. iOS 27 lets you reorder items in any container with .reorderable() and .reorderContainer(for:), and lets you use .swipeActions outside a List.
Build a list of trips grouped into sections by year, with swipe-to-delete and a second swipe action that marks a trip as a favorite.
After this lesson you should be able to answerForEach need each element to have a stable identity?