TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: dismiss() fails on random cases on iOS16

Forums > 100 Days of SwiftUI

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...

1      

I've just discovered the problem, after a lot of trying-error practice. And it was due to a modification I added to my tabbed main view, which is described here:

https://designcode.io/swiftui-handbook-tabbar-to-root-view

It generates conflicts with dismissing sheets pesented from that views. Just in case anyone use something similar.

Bests for all.

1      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.