I have my variables working and I have an array I want to cycle through to add text to a list of each of the variables in my array. Any ideas on what im doing wrong and how I can fix it? Thanks.
Here is my code:
struct ContentView: View {
@State var enteredText = ""
@State var textItems: [String] = []
private func updateTextItems(){
textItems.append(enteredText)
print("---------------")
for i in textItems {
print(i)
}
print("---------------")
}
var body: some View {
NavigationView {
Form {
Section(header: Text("Add Item to Array")) {
VStack {
TextField("Enter Text", text: $enteredText)
Button("Save", action: updateTextItems)
.buttonStyle(.bordered)
}
Section(header: Text("Items")){
ForEach(textItems) {textItems in
HStack{
Text(textItems)
}
}
}
}
}
.navigationTitle("Array Test")
}
}
}