UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Checking Todo List Items

Forums > SwiftUI

Screenshot

** also, how do you add images to posts?

As you can see in the screenshot (the text is in Norwegian) I'm trying to create a list of tags that can be turned on/off.

I want to use a a LazyVGrid with a ForEach, because the list/grid should be able to expand as people add tags

I thought this would be a piece of cake, but it turned out to be one of the most challenging issues I've faced in learning Swift and SwiftUI, thus far.

I assumed I could create code slightly as such.

struct Tag: Hashable { var title: String var checked: Bool }

then a list of [Tag] var tagList = [ LIST OF TAGS ]

and then put that into a ForEach and iterate over this. With a button to turn toggle the Bool on/off.

Alas, no such luck. Xcode keeps telling me that it is a Let constant (I suspect that this is due to the nature of Structs)

I tried a zillion different ways, but I keep coming back to the MVVM pattern, having to create a separate View and ViewModel to contain it all.. and it just becomes this huge ordeal (and I still can't make it work)

If anyone has an elegant solution to this, then I think the community at large would be grateful

2      

OK. So I found a solution. Presumably it's elegant, but it wasn't straight forward. In fact it was convoluted and really hard (for a noob like me).

If anyone wants a breakdown, let me know ;) Basically I found a great instruction on YT. Worth the time

2      

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!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

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.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.