Skip to content

Instantly share code, notes, and snippets.

@khanlou
Last active August 1, 2020 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khanlou/476f02913c31e68d9e36db3df0cec7fd to your computer and use it in GitHub Desktop.
Save khanlou/476f02913c31e68d9e36db3df0cec7fd to your computer and use it in GitHub Desktop.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment