|
I'm looking for some pointers on coding more efficiently.
|
|
Your code tells me you come from a background where you learned procedural programming.
You ask:
I would ask you to think about rock objects, and paper objects and scissor objects. Simplify your code by thinking about and using objects! Now ask yourself.
You don't have to noodle very long to realize your choices are rock, paper, and scissors. And
Now that you have a way to assign a Choice to your user, how do you get the iPhone to make a choice? What FUNCTION might you need to get a RANDOM choice? You can add functions to enumerations.
You have more work to do!
|
|
Note: @rooster has a complete rock, paper, scissors enum in the forum. But you asked for help and ideas. Please try to fill out the functions on your own before taking a peep at his code. |
|
Ah, I never knew about enum's RawValue identity. That helps things. However, I don't understand the following:
If |
|
Hover your mouse over the Click the name. It should tell you what kind of object you're over. It will tell you that One of the things that
In your application, you have a fully featured object with the name of You're correct! All you have to do is give that shiny new, fully featured Choice object a name! I suggested |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
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.