I’m making an attempt to position medication beneath sections correlating to their class however im getting a number of sections for every drug I add of the identical class. Im unsure how a lot this course of differs when utilizing mannequin macros.
Listing {
ForEach(activeStash) { drug in
Part(header: Textual content(drug.substanceClass)) {
NavigationLink(vacation spot: StashLinkView(stashed: drug)) {
Textual content(drug.substance)
}
}
}
}
Grouping however with duped sections Consequence:
Listing {
ForEach(activeStash) { drug in
Part(header: Textual content(drug.substanceClass)) {
ForEach(activeStash) { drug in
NavigationLink(vacation spot: StashLinkView(stashed: drug)) {
Textual content(drug.substance)
}
}
}
}
}
Resolution:
Listing {
ForEach(Array(Set(activeStash.map { $0.substanceClass })), id: .self) { substanceClass in
Part(header: Textual content(substanceClass)) {
ForEach(activeStash.filter { $0.substanceClass == substanceClass }) { drug in
NavigationLink(vacation spot: StashLinkView(stashed: drug)) {
Textual content(drug.substance)
}
}
}
}
}