Skip to content

Instantly share code, notes, and snippets.

@pixelmatrix
Last active June 6, 2019 20:31
Show Gist options
  • Save pixelmatrix/95aec6281fd56ef43c6fe4e6576de5ab to your computer and use it in GitHub Desktop.
Save pixelmatrix/95aec6281fd56ef43c6fe4e6576de5ab to your computer and use it in GitHub Desktop.
Using ForEach or List with a collection of Strings in SwiftUI
import SwiftUI
struct MyForm : View {
@State var items: [String] = [
"foo",
"bar",
"baz"
]
var body: some View {
VStack {
// Cannot access items directly because it must be "Identifiable"
ForEach(0..<items.count) { index in
TextField(self.$items[index])
}
Button(action: {
// handle action
}) {
Text("Save")
}
}.padding()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment