|
Hello there, and apologies for posting the same query on the wrong section of the forum I have completed somehow the Milestone: Projects 4-6, which seems to work ok apart from a logic bug that I have obviously inadvertently created, which caused a double refresh of the question, once after providing the answer and once again after tapping the continue button on the allert window. I would be extremely helpful if you could help me understanding what I did wrong on this specific issue. Many thanks in advance for your help. Ammo.
|
|
Ammo asks for clarity:
First, welcome to Hacking With Swift! We can help answer your questions. But you have to help us! Please edit your message and place ALL YOUR CODE inside the three back tick marks. ``` Second, please don't cross post in different forums! You can visit your other post and DELETE IT. Thanks. Third, you're on Project 4-6 ?? You did nothing wrong! You kicked your toe on a bump in the road. You are learning and asking the right questions. Keep this in mind...Think of a SwiftUI view struct like a small box. It contains a few variables, and some instructions on how SwiftUI should assemble the screen. This is a very small box. SwiftUI will DESTROY your box and recreate it hundreds, if not thousands of times when you run your application. Don't worry about it being created and DESTROYED and recreated. SwiftUI is very efficient at creating and destroying your RememberSwiftUI will destroy your So, when do you change your In your code, you allow your player to tap on one of three possible answers.
When a player taps the button, you execute code in your
This is why your questions are redrawn when you tap the correct (or incorrect) answer. NextNext you allow the player to tap the
Again, you're telling SwiftUI to DESTROY the old view and recreate it using the updated variables. This is why SwiftUI updates the questions after your player taps continue. Clear as mud? Finally: Keep Coding! |
|
Obelix, thanks a million for your full explaination. I think I need to digest it a bit, my mind does not seems to be particurarly flexible this days but I hope that with time and testing I will manage to get to fully implement your directions. Thanks again and have a great weekend. |
|
To address the logic bug causing a double refresh in Milestone: Projects 4-6, review your code for unintended loops or duplicate function calls. Check event handling and ensure proper execution flow. Debugging and testing are crucial for identifying and resolving the issue. For further assistance, provide specific details related to Budgeting Enterprise or the project code. |
SPONSORED Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!
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.