I have a array of string
fakeData = ["Array A",
"Array B",
"Array C",
"Array D"]
How Can I implement this array in ListView in SwiftUI ?
I have a array of string
fakeData = ["Array A",
"Array B",
"Array C",
"Array D"]
How Can I implement this array in ListView in SwiftUI ?
首先,您应该标记数组,就State
好像您要更改视图内的数据一样,或者不理会它,但我选择State
演示:
@State var fakeData = ["Array A", "Array B", "Array C", "Array D"]
然后只用一行代码从中列出一个列表:
List(fakeData, id:\.self) { Text($0) }
包起来:
struct ContentView: View {
@State var fakeData = ["Array A", "Array B", "Array C", "Array D"]
var body: some View {
List(fakeData, id:\.self) { Text($0) }
}
}