Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct ContentView: View {
- @State var items = [Item]()
- var body: some View {
- //1. Embed your View into a Navigation View
- NavigationView {
- List(items) { item in
- Text(item.name)
- }
- //2. Add a Title for your Navigation Bar
- .navigationBarTitle(Text("To-Do"), displayMode: .inline)
- //.3 Add the Bar Items
- .navigationBarItems(trailing:
- HStack {
- Button(action: {self.addTask()}) {
- Image(systemName: "plus.circle")
- }
- Button(action: {self.addTask()}) {
- Image(systemName: "minus.circle")
- }
- })
- }
- }
- func addTask() {
- let item = Item(id: items.count+1, name: "Sample Task")
- items.append(item)
- }
- func removeTask() {
- items.removeLast()
- }
- }
- struct Item: Identifiable {
- var id: Int
- var name: String
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement