I am writing an Library app that shows a grid. Each grid location shows the book cover and some info about the book. If the user clicks on a cover, the detail view opens. One option that the user has is a delete the book button. This button deletes the book from SwiftData, but the detail page remains populated. The simple way I want to handle this is to have the delete button also return to the grid view (eg root).
Here is the relative code from the CurrentView
@State private var path = [Book]()
var body: some View {
NavigationStack(path: $path) {
BookListView(sort: sortOrder, searchString: searchText)
.navigationTitle("Library")
.navigationDestination(for: Book.self, destination: EditBookView.init)
.searchable(text: $searchText)
Here is the code from the Grid View
var body: some View {
LazyVGrid (columns: gridLayout) {
ForEach(books) { book in
NavigationLink(value: book) {
GridRow {
VStack {
Here is the code from the Detail View
var body: some View {
Form {
VStack (spacing: 0){
BookImageView(book: book)
}
TextField("Title", text: $book.title)
Button("Go Back to ListView",
action: {
// Action to perform
})
}
.navigationTitle("Edit Book")
.navigationBarTitleDisplayMode(.inline)
} // Form
} // some View
Can you provide the code for the button "Go Back to Last View"