I'm now finishing my app after finishing the course, and has encountered an strange behaviour on dismissing sheets. It seems it has started with iOS16, I'm not sure, and I'm even even considering it an iOS16 bug, as it appears on an aparently random basis.
I use on all my modal views the simple method to make them dismiss themselves:
@Environment (\.dismiss) private var dismiss
I use this, mainly, for adding and editing Managed Objects on Core Data: from entity list, modal presenting sheet for adding items. Everyhting works perfectly.
But, in some cases, dismiss doesn't work: it tries, but modal view dissapears abruptly. More strange even: after so, this behaviour spreads to the rest of dismisses, of another views. After "killing" app, and restarting, everything works again, until any new random moment...
I've been dealing whit the information given here: https://www.hackingwithswift.com/forums/swiftui/presentationmode-wrappedvalue-dismiss-breaks-when-underlying-view-is-updated/4320
So, moving dismiss() method to be called first:
Button {
dismiss() //<- dismiss here...
//Core Data saving methods.
//dismiss() <- ...instead of here
}
Saving works perfectly on both cases, but dismissals strange "breakings" persists in some cases. And never with a logical pattern. Does anybody could help me about how to detect the origin of the problem?
By the way: debuging this error on XCode throws no error code at all on console. So no way to find a clue...