|
I have written code to select from two lists of strings, with two "boxes" on screen. It works, no problems.
It would be a nightmare to add more selections.
How would you write this using the swiftui coding phylosophy? Hard coding like this just does not work so well
Just looking for ideas on how to handle these types of things
|
|
The best way to reduce complexity in SwiftUI is to refactor your It also helps to take advantage of Swift's powerful type system, especially Anyway, here's one way it could be done:
I hope I've added enough commennts to explain what's going on. If you need more help understanding, don't hesitate to ask. |
|
slight typo in the foreach, s/b GolfSequenceItem, but other than that, works fine. Just what I was looking for. Old School was create a dimension in the array. Swift Scool, create a view of the dimension. Lovely... I've used enums for ages, but I'm still struggling with the power of them in the Swift environment. Thanks for the lesson |
|
Ack, sorry about that. I was making tweaks and updating my post as I did so and must have gotten a little out of sync between Xcode and the post. It should be:
Though just for giggles, here's what I tweaked it to that caused my mistake:
And then in
Either way works fine, but go with whatever works best for you. (I also looked at |
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.