What’s the difference if we write
myArray is a object of strict which has only two items An id and name
List(self.myArray, id: \.id) { currentArray in
....
}
And
List {
ForEach(self.myArray, id: \.id) { currentArray in
......
}
}
myArray is a object of strict which has only two items An id and name
List(self.myArray, id: \.id) { currentArray in
....
}
And
List {
ForEach(self.myArray, id: \.id) { currentArray in
......
}
}
Another benefit of nesting a ForEach inside a List is the ability to add static elements to the list. Say for example you want to show a button above the list. You could do it like this:
Code Block struct SwiftUIView: View { var items = ["item01", "item02", "item03"] var body: some View { List { Button("Add new item") { print("Adding new item") } ForEach(items, id: \.self) { item in Text(item) } } } }