|
Hello, I need some help, I have a custom alert that based on its value should show a certain message and buttons, but sometimes 'if else' statement in alert action block seems to be totally ignored and just shows an 'OK' button. I would be grateful if someone has a solution to this very strange problem for me. I hope it's clear what I mean, but I'll provide more code if needed. |
|
@yoid alerts us all to an issue:
First: Source Code!First, I have not taken a detailed look at this issue you're having. Why? Because you made it very difficult for me to test in my own development environment. Why? Because you included screen shots of code, rather than actual code. Please help us to help you. Take a moment to review the markup tag for adding code to your forum questions. See -> Adding Code snips to Forum Messages SecondI reviewed SwiftUI documentation for initialising an
✅ You're providing a titleKey as a localized string. But you've noticed that the I don't see all your code. However, your
Would like to see how you defined your ThirdPut business logic into your view model. Your architecture suggests you're using a view model to handle the state of your application. If so, consider removing your business logic from the view and placing it inside your view model. Use the view to show the state of your model. Write the view model to expose only the functional intentions of your businss logic. Here, your intention is to delete the pending selections. Hide all the internal steps to do this. Only expose a single intention. Example:
Keep Coding! |
|
Obelix, please accept my apologies and the requested information will be posted below. View
ViewModel
I hope this extension is answer of your wondering on Boolean present
The logic specifically for the alert buttons has been moved to the view model as you suggest, let me know if I missed anything. |
|
I actually have a view that through an if else statement condition shows Content Unavailable WorkingListView or Content Unavailable and there I've mistakenly attached another alert modifier and that's where the conflict comes from... I thought about Obelix comment and started to move all the business logic, that's how I found the 'bug' quite by accident.
|
|
Not an accident! That's a debugging skill! However, I think the idea of mixing view logic and business logic clouds your mind sometimes. You may be looking for a logic error, but your eyes are tricked by the view logic. One can hide the other. Well done finding your bug. Since this is a sharing community, thanks for posting your code and working code. However, It would have been nice for you to point out the flawed logic, and the fixed logic with You can go back and edit your existing message, and add a few comments on what was incorrect, and what you did to fix the bug! Well done! Keep Coding! |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's all new Paywall Editor allow you to remotely configure your paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.