Post

Replies

Boosts

Views

Activity

Reply to How to make an updatable ForEach loop SwiftUI
@Claude31 The ForEach is as follows (sorry about formatting): VStack { ForEach(Array(flags.keys), id: \.self) { flag in HStack { Spacer() Button("Delete") { print("delete \(flag)") }.padding() Toggle(isOn: $isActiveToggleOn) {}.padding().onChange(of: isActiveToggleOn) { if isActiveToggleOn { print("activate \(flag)") } else { print("deactivate \(flag)") } } Spacer() Text(flag).padding() Spacer() Text(flag).padding() Spacer() } } }
Sep ’24
Reply to How to make an updatable ForEach loop SwiftUI
what do you expect to get ? display text per child: where are the children defined ? where and how do you add flags ? I wanted the ForEach loop to update every time I added a value. What @B347 told me was helpful because I was able to reduce the amount of incorrect "hey"s added to my view, however did not solve the issue. The children are defined in the same place you add flags. There's a seperate window which opens that allows users to enter flags and values (this works properly). This is a seperate file within the app, however the flags dictionary can be accessed from other files. An advice: study an Apple tutorial on Swift and SwiftUI. It seems there are some basics you are still missing. I have covered the basics many times, I would not call this basic however what I learnt may differ from what you did.
Sep ’24
Reply to How to make an updatable ForEach loop SwiftUI
Thank you for your response, The "hey" constant was intended behaviour, and I tried your answer. I noticed that it did indeed put the flag and only the flag in the view with no extra iterations, however it didn't update (what I wanted). Also I was wondering how to get the flag value in the ForEach (there is no flag.value) This was very helpful though!
Sep ’24