SwiftUI & SwiftData.
I have a view that lists SwiftData objects. Tapping on a list item navigates to a detail view. The list view also has a "New Object" button. Tapping it opens a sheet used to create a new object. There are, obviously, two possible outcomes from interacting with the sheet — a new object could be created or the user could cancel without creating a new object.
If the user creates a new object using the sheet, I want to open the detail view for that object. My thought was to do this in the onDismiss
handler for the sheet. However, that handler takes no arguments.
What is best practice for handling this situation? In UIKit, I would return a Result<Object, Error> in a closure. That won't work here. What is the "correct" way to handle this that is compatible with SwiftData and the Observation framework?