The List in SwiftUI is like the UITableView in UIKit, which is used to show the contents of an array in the vertical direction.
Make the first List.
List(0 ..< 5) { item in
Text("Hello World!")
}
It makes a List, and the List has five lines by default.
Make the second List.
Add three Texts to the List to show three records.
List {
Text("Apple")
Text("Banana")
Text("Pear")
}
Next, Make the third List.
Add an array as the List's data source.
Add a ForEach statement to iterate through the array.
Use Text to show strings.
A List will be made based on the data source.
let colors = ["Red", "Green", "Blue"]
var body: some View {
List {
ForEach(colors, id: \.self) { color in
Text(color)
}
}
}
Follow me on:
Comments