|
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 |
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
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.