Post

Replies

Boosts

Views

Activity

Reply to How to make an updatable ForEach loop SwiftUI
Hi, you are working with a dictionary type. you have some issues in your code: This loop iterates from 0 to flags.count. flags.count returns 1 since there’s one item in the flags dictionary. But the loop will iterate from 0 to 1, meaning it will run two times, which may not be the intended behavior. This could lead to an off-by-one error. AND: you are not showing the dictionary entry in your Text View. You have to iterate over your Dictionary-Type. You are showing just the constant "hey". you have to change the code to something similar to: like ForEach(Array(flags.keys), id: \.self) and... Text("\(flag)") would propose you go to doc about dictionary. https://docs.swift.org/swift-book/documentation/the-swift-programming-language/collectiontypes#app-top)
Sep ’24