ForEach loop을 이용해서 같은 것을 여러번 반복해서 타이핑하지 않고도 출력하는 방법
import SwiftUI
//we don't wanna rewrite the same text or code like 100 times -> ForEach 사용
struct ForEachBootcamp: View {
//create a data set
let data: [String] = ["Hi", "Hello", "Hey everyone"] //an empty array
let myString: String = "Hello"
var body: some View {
//예시 2
VStack {
ForEach(data.indices) { index in
Text("\(data[index]): \(index)")
}
}
//--------------------------------------------------------
//예시 1
VStack {
//each of this loop has an index and index is just the loop number that it's on.
ForEach(0..<10) { index in
HStack{
Circle()
.frame(width: 30, height: )
Text("Index is: \(index)")
}
}
}
#Preview {
ForEachBootcamp()
}