|
Hi all Im loving the 100 days of swiftui course. im on day 25 now. i worked hard on this challenge and wondered if i could have some feedback please on my code. ive not gone for fancy pics and backgrounds with this, just wanted to get the logic and code practice right. somit doesnt look flashy but it works. I originally coded seperste views for the computer choice but found that any @State variables I placced in the view struct would not be available to use in the other structs. i couldnt work out how to set them so they were available everywhere. Any tips would be appreciated. im using swift 4 playgrounds on ipad at the mo. thank you! layth
|
|
When you reach project 7 you will begin to learn how to do what you are asking about here. I would recommend just getting the project to work, and continue going through the course material. But if you want to jump ahead and try to learn about those things now, you can follow this link When I first started trying to work through the 100 days course, I spent many hours trying to make extra features work on some of the projects, and I often found that if I had not wasted my time on trying to mess around with the code, I would have learned what I wanted to do in a fraction of the time by just continuing on to the next project where I would have had it explained to me in a simple way. |
|
The
What are you trying to accomplish by using |
SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community! Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
thanks @Fly0strich - i did wonder if all would become clear and youre spot on ive been messing around trying to add stuff. fun though! @Roosterboy - i was just messing around really - i thiught that by setting it like that it protected it from being alterered from elsewhere given its a highscore. you wouldnt want it being changed by anything other than the playing the game. but i also take your point. thank you! |
|
Right of the bat: You should add
Also if the game asks you to lose and if you chose the same thing as the computer chose you get a point. I presume this is unwanted because you didn't actually lose, but instead tied. I'm not going to provide an answer unless you ask me explicitly since you should try doing it yourself. Finally consider adding background color to buttons and images to make them easier to see. |
|
This is how I tackled Day 25 Challenge. Any feedback for improvements welcome and much appreciated!
|
|
@tomn Well done again! Congrats with a new milestone ! Even being a new guy to coding I'd like to put my few words. First of all:
Now code:
Looks like It has never been used in your code eventually. Or not ?
do you have any previous experience with Swift/UIKit ? I don't remember Paul has been showing us such a thing to use for modifying NavigationBarTitle's color before day 25. hmm ? :) Maybe I've also seen a small bug after ending the round. I somehow got a poping alert with score 0, even though it should be the restart and new selection should begin so it shouldn't be possible to get the alert before making any choice. Hmmm. Great job anyway ! |
|
Tom asks for a code review: This code is correct. But start looking at this with a critical eye.
You have three variables and must keep the Think to yourself, "If I'm changing the
Using a computed variable ensures that whenever
Keep coding! |
|
@ngkmn14 Thanks for the feedback and the advice.
@Obelix Definitely here to learn Swiftly ways of doing things. Much appreciated. gameOver was a @State private var, and was used in the following way.
When I change gameOver to a computed property, .alert can't find '$gameOver' in scope anymore. Do I have to dynamically bind it somehow? |
|
@Obelix I made the following changes. How does it look? I couldn't figure out how to bind a computed property to .alert(), so I still had to do an if else statement in one of the methods to toggle showingGameover to trigger the game over alert. But gameOver is now a computed property depending on the current question counter. Also improved the UX a bit. Now the number of turns which I'm showing on the screen, only update after clicking away the score alert.
|
|
Tom upgrades his code!
I think the code
But since you asked... now look at the If you're playing Rock, Paper, or Scissors with someone and you ask them "what is your favorite move?" Is If my team were reviewing your code, they might ask you to reconsider this design. (Actually, they would insist you redesign this code!) So what are the only valid options? And what have you learned in Swift that allows you to define a strict set of possible values? See -> Day 3 Concepts |
|
@Obelix asks:
I'd then use an enum, make it CaseIterable, and call a random element on all cases of the enum. Many thanks again. |
SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!
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.