|
After finishing all 8 rounds when I press on the correct answer it doesn't show the alert. And when I press on something else it immediately shows the Finished alert even though I'm resetting the numberOfRounds variable
|
|
Every time you see a view on screen, it's representing a STATE of your game. You think your game is in ONE state and should have a particular look, or alert showing. But you are confused when you see alert boxes appear when you're not expecting them. Blinking LightsOne technique you should add to your toolkit is to add temporary Example:
As you play your game, ask yourself: NoteYou could use either syntax:
Either is fine. I prefer the second because I can modify the text to help frame the event and describe my intentions.
|
|
I guess we could just tell you the answer. (Someone probably will.) But at this point in the 100 Days story, I'd recommend you learn some techniques that will help you evaluate and debug your code. In some respects, debugging your logic might be 70% of learning SwiftUI programming! Take a crack at solving this using the blinking light technique. Please report back what you find! |
|
@Obelix Thanks for your help. After studying my code and following your tips, I realised that setting |
|
Nice! It's still a useful technique to add blinking lights to your views. They'll give you a great idea when each Red fields? Animated flags? New buttons? You control how the views appear based on Please do us a favor and mark your answer as "Solved", seeing as how you found your logic error. |
|
Here a possible way to keep thing tidy and easier to manage Create a file called AlertItem, and put this in
Then you can add the alerts required EG.
Then in your ViewModel add your properities and methods
This will make your View have only one alert and no logic
I use this as easy to add new and manage alert messages because they are all in the same place |
|
Very nice and professional approach, Nigel. On which day of 100 days of SwiftUI are you? Hope I could code like this soon... |
|
I have finished it (twice!). but I am sure that you will get there. Sometimes write code that works then look at how to refactor to more managable section. Like the alert if only had one in project then the above code would not be worth doing, however found that quite often alerts are need in code but only when the unhappy route is taken but they just clutter up code for the "happy" route. I used to used |
SPONSORED Transform your career with the iOS Lead Essentials. Unlock over 40 hours of expert training, mentorship, and community support to secure your place among the best devs. Click for early access to this limited offer and a FREE crash course.
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.