SHARE
TWEET

Untitled

a guest Sep 18th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct ContentView: View {
  2.    
  3.     @State var items = [Item]()
  4.    
  5.     var body: some View {
  6.         //1. Embed your View into a Navigation View
  7.         NavigationView {
  8.             List(items) { item in
  9.                 Text(item.name)
  10.             }
  11.             //2. Add a Title for your Navigation Bar
  12.             .navigationBarTitle(Text("To-Do"), displayMode: .inline)
  13.             //.3 Add the Bar Items
  14.             .navigationBarItems(trailing:
  15.                 HStack {
  16.                     Button(action: {self.addTask()}) {
  17.                         Image(systemName: "plus.circle")
  18.                     }
  19.                     Button(action: {self.addTask()}) {
  20.                         Image(systemName: "minus.circle")
  21.                     }
  22.                 })
  23.         }
  24.     }
  25.    
  26.     func addTask() {
  27.         let item = Item(id: items.count+1, name: "Sample Task")
  28.         items.append(item)
  29.     }
  30.    
  31.     func removeTask() {
  32.         items.removeLast()
  33.     }
  34. }
  35.  
  36. struct Item: Identifiable {
  37.     var id: Int
  38.     var name: String
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top