Skip to content

Instantly share code, notes, and snippets.

@apatronl
Created September 2, 2020 13:35
Show Gist options
  • Save apatronl/50a572e0e775b4d04eae2a368ba91bfb to your computer and use it in GitHub Desktop.
Save apatronl/50a572e0e775b4d04eae2a368ba91bfb to your computer and use it in GitHub Desktop.
struct ContentView: View {
@State private var newTodo = ""
@State private var allTodos: [TodoItem] = []
var body: some View {
NavigationView {
VStack {
HStack {
TextField("Add todo...", text: $newTodo)
.textFieldStyle(RoundedBorderTextFieldStyle())
Button(action: {
guard !self.newTodo.isEmpty else { return }
self.allTodos.append(TodoItem(todo: self.newTodo))
self.newTodo = ""
}) {
Image(systemName: "plus")
}
.padding(.leading, 5)
}.padding()
}
.navigationBarTitle("Todos")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment