|
This was to be my solution to displaying more meaningful error information in an Alert for Checkout View. When, however, I disable wi-fi, the Alert is not displayed. It calls my error handler (which I added because I understand that you can't throw inside the completion handler) and it places the correct error message into the errorMessage property and it toggles my $showingErrorAlert to true. I can't understand why the Alert is not displayed? Here is my Checkout.View !
|
|
Try attaching one of those |
|
I had the same problem while doing this project, and read somewhere online that it is not possible to use two .alert modifiers on a single view. This makes sense if you think about other modifiers that you can add to views. For example, if you try to add a .font modifier to a Text view, and then add another .font modifier immediately after it, only the second modifier you added will be in effect. In this project, I ran into the problem where only one of the .alert modifiers was in effect, even when I added one .alert modifier to the Button itself, and the other .alert modifier to my GeometryReader that the Button was contained in. I think it has something to do with the alert(isPresented: ) condition for both of the alerts being triggered by the same button, so there isn't a good way to separate them. The only solution I was able to find was to kind of multi-purpose the @State variables for both situations. Either way, when you press the button, an alert is shown, but the title and message of the alert would just be different depending on whether there was an error or the order was completed successfully.
I admit, this doesn't seem like a very professional solution, but it gets the job done I guess. |
|
One neat way to handle multiple
|
|
|
|
To an optional (Although in looking at the changes and new stuff in SwiftUI 3, it looks like this initializer has been deprecated going forward. I haven't really explored the new stuff much, so I'm not sure if there's an equivalent. That would suck if there isn't, IMO, because it's so useful.) |
|
Thank you @FlyOstrich and @roosterboy for your help. I decided to adopt the .alert(item:modifier:) approach suggested by roosterboy.
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.