swiftui foreach example
Example 1: for each swiftui
struct ContentView: View {
let colors: [Color] = [.red, .green, .blue]
var body: some View {
VStack {
ForEach(colors, id: \.self) { color in
Text(color.description.capitalized)
.padding()
.background(color)
}
}
}
}
Example 2: foreach swift
let numbers = [1, 2, 3, 4, 5]
for number in numbers {
print(number)
}