SwiftUI provides several ways to iterate over collections, including the ForEach loop.
Unlike a SwiftUI List, which represents views in a single column, similar to a UITableView, ForEach provides more flexibility to break away from the single column. This can be useful for more complex repeating layouts, although you don’t get the same functionality found in a List, such as swipe gestures. This tutorial will cover some examples of when to use ForEach.
The following shows a very basic ForEach loop:
var body: some View {
ForEach(0..<5) { index in
Text(index.description)
.frame(width: 60, height: 30)
.background(Capsule().fill(Color.blue.opacity(0.6)))
}
}