This is designed to look like sheet(item:content:)
:
func sheet<Item, Content>(item: Binding<Item?>, content: @escaping (Item) -> Content) -> some View
But for pushing views instead of presenting them as sheets.
To use it, create a @State
variable for your selected item:
@State var selectedPerson: Person?
Then, chain at the end of your view:
.pushView(item: $selectedPerson) { person in
PersonDetail(person: person)
}
If you need mutation, your Item
type should probably be some kind of ID or index with which to fetch the item, otherwise you will end up with stale data.