loading...

CS193p Notes - Lecture 10: Navigation + TextField

lankinen profile image Lankinen ・2 min read
  • 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

Posted on by:

Discussion

pic
Editor guide