Skip to content

Instantly share code, notes, and snippets.

@gaeng2y
Created August 4, 2024 11:04
Show Gist options
  • Select an option

  • Save gaeng2y/49e01cc718282ee8fdbfbf6e2354d027 to your computer and use it in GitHub Desktop.

Select an option

Save gaeng2y/49e01cc718282ee8fdbfbf6e2354d027 to your computer and use it in GitHub Desktop.
struct ContentView: View {
@ObservedObject var store = Store.shared
@State private var newItemText: String = ""
var body: some View {
VStack {
TextField("New Item", text: $newItemText)
Button(action: {
Dispatcher.shared.dispatch(action: .addTodoItem(text: newItemText))
newItemText = ""
}) {
Text("Add Item")
}
List {
ForEach(store.todoItems.indices, id: \.self) { index in
Text(store.todoItems[index])
.onTapGesture {
Dispatcher.shared.dispatch(action: .removeTodoItem(index: index))
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment