How do we pass a selected item to a sheet?

I have view showing a list of contacts. When the user taps one, I want to raise a sheet that shows the contact's phone numbers and E-mail addresses and lets the user pick one.

When the user taps a list entry, I store the associated Contact object into a @State variable called selectedContact. Then I set the boolean that's bound to the sheet modifier's isPresented flag. That modifier:

.sheet(isPresented: $showContactMethodSheet, content: { ContactMethodView(withContact: selectedContact!) })

But the app crashes, because despite selectedContact having been set. It looks like the sheet was pre-built with a nil selected contact upon view load. Why, and what is the expected approach here?

Further research reveals that you have to use an alternate form of .sheet, which takes an "item":

.sheet(item: $selectedContact, onDismiss: { sheetDismissed() }, content: { contact in ContactMethodView(withContact: contact) })

I had seen references to this, but without explanation of how the sheet is triggered. It turns out that it's triggered when the "item" binding is non-nil.

I'm curious as to why you'd want the behavior of the other method. It seems error-prone and aggravating.

They’re cases where you might want to use sheet(isPresented:onDismiss:content:) , this is because the state is explicitly available to your app via the boolean binding.

In cases where the presentation state is better modeled by the absence or presence of a value rather than a boolean use sheet(item:onDismiss:content:). This modifier taking a binding to a nullable data model.

Thanks for the reply. I'm not questioning the existence of the two invocation methods. I'm asking why you would want the (IMO) defective behavior of the isPresented version of .sheet. In that one, if the closure for content tries to pass an object from the invoking view to the sheet for display, it is out of date. For example, you're showing a list, and when the user taps an item, you want to pass that item to a sheet so the user can select something from it. But this doesn't work; the sheet doesn't get the current value of the selected-item variable. There are posts and questions galore online about this problem.

Now the problem with the item:onDismiss:content version is that you have to nillify the item reference to dismiss the sheet. So how are you supposed to return data from the sheet? I ended up having to change the item from a struct to a class and junking it up with some state variables so I could pass it to the sheet and then store the selections the user made on the sheet. And of course I need a copy of the selectedItem variable because I have to nillify the one that triggers the sheet.

Am I missing something here, or does the design of this thing stymie the programmer at almost every turn? What I'm doing is, I would bet, an extremely common workflow. Why does it require such cumbersome gymnastics?

And this appears to be another example of the conflict between "prefer structs" and "the single source of truth." Structs are copied all over the place, which thoroughly breaks the single-source paradigm. And you can't fix it here with a binding.

How do we pass a selected item to a sheet?
 
 
Q