-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SwiftUI ForEach? #64
Comments
Hi Michael, there hasn’t been any special work done for this. I’m not sure how |
The error message I get that seems to get right to the point is: Generic struct 'ForEach' requires that 'OrderedDictionary<String, Any>' conform to 'RandomAccessCollection' |
Thanks for the tests. I’ve looked into why this is and I couldn’t find any reason not to conform to As a temporary workaround, you should be able to convert your |
I've experimented with using your OrderedDictionary (and indeed Dictionary) with ForEach, and decided the results that are specific to working with SwiftUI called for a different approach, and did that. I do have an array but had to make a slightly different arrangement to accommodate the ForEach. I would for sure recommend holding off on any changes until after WWDC; I expect Apple to offer one, perhaps two minor adjustments to the SwiftUI pantheon that could affect development outcomes, like the existing SwiftUI code in my project. Thanks! |
OrderedDictionary can be used with
Note that conforming |
@crenelle: I’ve looked into this issue and although I most likely will be able to make The simplest way is to base it on indices as follows: ForEach(orderedDictionary.indices) { index in
let (key, value) = orderedDictionary[index]
// Use index, key, value
} If you want SwiftUI to keep track of elements’ identities, you can make the keys conform to ForEach(orderedDictionary.orderedKeys) { key in
let value = orderedDictionary[key]
// Use key, value
} I hope this helps. If you have any follow-up questions, let me know. Edit: You might need a conversion to |
I'm curious to learn whether this OrderedDictionary can work with SwiftUI ForEach.
The text was updated successfully, but these errors were encountered: