DEV Community

Lankinen
Lankinen

Posted on

CS193p Notes - Lecture 10: Navigation + TextField

  • popover(...)
  • ViewModel is passed to subviews using @EnvironmentObject
    • Add var with @EnvironmentObject property wrapper to the sub view and give @ObservedObject ViewModel to it by adding .environmentObject(self.viewModel)

Navigate to another view by clicking an item

NavigationView { List { ForEach(store.documents) { document in NavigationLink(destination: EmojiArtDocumentView(document: document)) { Text(self.store.name(for: document)) } } } } 

Delete items from list

List { ForEach(...) { ... } .onDelete { indexSet in indexSet.map { self.store.documents[$0] }.forEach { document in self.store.removeDocument(document) } } } .navigationBarItems( trailing: EditButton() ) 

@RealLankinen

Originally published here

Top comments (0)