I've referenced this tutorial for using a button action to dismiss sheets https://www.hackingwithswift.com/quick-start/swiftui/how-to-make-a-view-dismiss-itself
but I'm having trouble extending the idea to my usecase below:
I return a success from the server and switch the published property
As far as the view goes, I have the parent view with a button to bring up the sheet using the typical binding and modifier:
Inside of the sheet, I only use a navigation bar item for a "Cancel" button which will dismiss the sheet:
The goal is for the sheet view to be listening for the change in my @Published property so that it will dismiss once the server returns the successful response.
Nothing seems to be working.
Any help would be great!
You have not shown how you have defined the class that has the @Published parameters, so I have taken Paul's example code and modified it to be for a class instead. Hopefully this will give you some ideas of how to change your code.
If you did use this idea in the simplest program where there is just a ContentView, you would need to change the app swift file to prevent a compliation error.
Hi @Greenamberred I'm not sure I understand what you mean about the class with the @Published parameter. The only class involved is my View Controller with the
I've given this a shot and still am not finding the right results. If I understand, your private function which runs the
Let me know if I can share some more context or code on this because maybe my navigation and Sheet hirearchy is causing some of the problems?
Thanks for the help!
Yes, seeing the code for the view would be useful to try help you more specifically.
Somewhere you should be using the equivalent of
but using your parameters
I'll just drop the entire view for you. This is a user account view, with a sheet to change their password. As I mentioned, the goal here is to dismiss the "change password sheet" once the @Published property switches to True from my class.
I think ultimately what doesn't make sense is how I "listen" to the @Published property while at the same time bind to the local @State properties in my view that manage the sheet as well.
Ignore all the Account Image stuff.
SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.
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.
Link copied to your pasteboard.