|
I have this view below that basically slides in a Rectangle with color after 3.5 seconds. But I'd like to refactor the code to allow for more slides and not have to do an if-else for each. What would be the best way to go around doing that? How would you guys "clean up" this code? I'd start with creating an inner Rectangle view to contain the similar codes but what do I do with the show1/2/3 code? thanks in advance, Jayson
|
|
You could use a enum.
Then use a switch statement and switch on show. In your task set show to the enum case you want to show. |
|
SPONSORED 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! Hurry up because it'll be available only until April 28th. Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
Updated code implementing switch. I tried using an array approach hoping to just go through each array item and cycling through it. I have a viewArray property I can use but for the life of me, I can't figure out how to have it cycle through each array item and then loop back to the start with .transition(.slide) Can anyone point me to the right direction? I am hoping to have the code work with any number of colors I place in the Enum / array. As of now, I'd have to manually place each case in the switch body. thanks, |
|
Try this:
|
|
|
|
And when the state of the view is reset the view is redrawn and as a result the new color is visible. Some SwiftUI modifiers require a certain order. As I understand is that |
|
|
|
Since the Instead of using a separate
This version of |
|
|
|
Ah, didn't even notice that. Sorry! |
SPONSORED 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! Hurry up because it'll be available only until April 28th.
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.