|
I'm currently working through Day 35 for the edutainment app. To me this app feels like it could be really similar to GuessTheFlag when it comes down to the game logic, so I'm working in that direction. However, I'm having a hard time translating some of the logic from GuessTheFlag to this project for a number of reasons. So far, this is what I'm trying to accomplish:
My goal is to generate three random answers for a user to choose from (they each appear in a blue box), while only one of them is the correct answer. Again this is super similar to GuessTheFlag but I'm stuck on implementing it. How do I generate both the random answers and the correct answer for a user to select? |
|
@swiftdoc is mixing what the program does with what the program shows....
Take your big problem and break it down into several, smaller solvable problems. To make it easier, put each problem in a separate room in your house, and only solve the problem in that room. Don't try to solve two problems at once. Problem #1You have two numbers, Rather than having a bunch of logic polluting your Game LogicYour game logic can all be neatly packaged into a convenient
Problem #2Now that you've created a
Problem #3Now that you have a Possibly you'll want to show a success message when the player selects the correct answer. Maybe the New Problem What did you learn?First, pull your logic into Second remember that SwiftUI is declarative. Re-read that statement. It's declarative. Declare what you WANT TO SEE. I want to see three options from this array of Don't multiply the two operands in your Full Example
Keep Coding |
|
HomeworkThere's a bug in the How can you solve it?? Please return here with your solution. |
|
Homework #2The But in the sample code above, I created a computed variable in the This violates one of the lessons from above namely, keep your game logic in a separate struct. Can you think of a way to move the Keep CodingPlease return here and let us know how you solved this. |
|
|
|
The solution for the picker bug was using an Further, the |
|
To get the Another step was to cut out the To have this reflect in the UI, I added I may have missed something here, but your responses were very helpful and I now have a much better development process :) |
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.