This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hi everyone.
I'm trying to make a Sectioned list dynamically. My problem is I want to create these Sections based on Core Data entity properties (unique).
For example, I have a list of Items which have the property .type of type String. I want to create Sections based on the item type. However the issue I am running into right now is that if I have 5 items, then there will be 5 sections, even though there are only 2 UNIQUE 'sections'
List{
ForEach(filteredItems, id: \.type){item in
Section(header: Text(item.type!)) {
ForEach(filteredItems.filter{$0.type == item.type}){item in
NavigationLink(destination: ItemDetail(item:item,
mediaItems: PersistenceController.shared.imagesFromCoreData(object: item.image)!
)){
ItemRow(item:item)
}
}
}
}.onDelete(perform: removeItem)
}
In the code above I have filteredItems, which is a list of Items. Again, each Item has the string property 'type'. I want to have the Type has a Section, and then Items that have that certain Type under that section. I believe this part is working as intended with the nested ForEach loop.
I think the issue is with my outer ForEach loop as it is looping for each item in the list. I thought the
id: \.type would solve this issue but it seems I'm not fully understanding this.
Hopefully someone can chime in with a solution?
Thanks all!
Subreddit
Post Details
- Posted
- 3 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/SwiftUI/com...