|
Working towards selecting two colors and the number of rectangles to create a color array. I'd like to create a func to make this reusable once it's useful. First I am just trying to make it so you can choose the number of rectangles dynamically like here This code works but you can't change the number of Rectangles without doing it in the code:
Here's my effort to add the number of Rectangles picker. I'd really like to clean this up. I got cautions telling me to change var to let, but r, g & b ARE changing values so something is off.
I'm repeating the math, there are Anyway, open to all kinds of suggestions.
|
|
Try this:
|
|
I'm sorry I haven't replied in 16 days. Your response floored me. I need to try to summarize to see if I can learn. You made a function called I'm trying to understand all it took for you to get there. To start, you make an Even using CGFloat instead of Double, has me praying I don't actually have to get this to get this: what is
In the Color extension, we made that variable called Any we use those components now to create our What I haven't seen before and not sure why but you use 'with' and then make the
Thank you so much for creating a solution. It's a huge leap for me to "kind of" understand this! |
|
I did it as an extension more so that it can be called on an existing So:
rather than something like:
It just reads better and is more "Swifty".
The In this particular case it doesn't really make much of a difference, but As for the
So using an argument label called
instead of this:
It just reads cleaner. I'm not exactly sure what you mean by "and then make the |
|
Thank you for the detailed explanation. I mistakenly used the term "modifier" incorrectly-- thinking of modifiers for views... I'm still wroking through your code, but it works and next I'm going to try adding the color pickers. I really appreciate your help- and patience!! BTW, you aren't ever on codementor are you? |
SPONSORED From March 20th to 26th, you can join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer!
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.