✨ForEach examples
Loop over a range of integers
// init(
// _ data: Range<Int>,
// content: @escaping (Int) -> Content
// )
// ---------------------------------------
// ForEach<Range<Int>, Int, Text>
// Data = Range<Int>
// ID = Int
// Content = Text
struct ContentView: View {
let positions = ["First", "Second", "Third"]
var body: some View {
ForEach(0..<positions.count) { index in
Text(positions[index])
}
}
}
Last updated
Was this helpful?