Last active
June 6, 2019 20:31
-
-
Save pixelmatrix/95aec6281fd56ef43c6fe4e6576de5ab to your computer and use it in GitHub Desktop.
Using ForEach or List with a collection of Strings in SwiftUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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