A List shows a row for each item you supply, in a single column:
List {
Text("A List Item")
Text("A Second List Item")
Text("A Third List Item")
}
Because the example is using a list of Landmark
objects, they have to be Identifiable
, so there's an id
parameter for each one.
The syntax is saying:
- Go through each item in the set of
Landmark
objects: landmarks
- Create a variable we can refer to when we're using each one:
landmark
- Add a row using the
LandmarkRow
view, and supply the current landmark
to that view so the view can use the data.
In Xcode if you put your cursor onto a variable, you'll see where else that variable is used, so if you click on landmark
on the first line of code you shared, it would be highlighted in the second line, too:
List(landmarks, id: \.id) { >->->landmark<-<-< in
LandmarkRow(landmark: >->->landmark<-<-<)
}