I am trying to iterate a @Published dictionary from a viewModel in a view in SwiftUI. I get an error saying that:
Initializer 'init(_:id:content:)' requires that 'Dictionary<InterestDomain, Bool>.Keys' conform to 'RandomAccessCollection'
How can I iterate a dictionary inside a ForEach? this is my code:
ForEach(viewModel.userDomains.keys.indices, id: \.self) { index in
VStack {
DomainOfInterestElement(isActive: self.$isActive, domain: self.viewModel.userDomains.keys[index].name)
if index != self.viewModel.domains.count - 1 {
Divider().padding(.bottom, 12)
}
}
}.padding([.trailing, .leading], 12)