Coming soon - Get a detailed view of why an account is flagged as spam!
view details

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.

3
Sectioned Lists and ID not working
Author Summary
Starky_D is in Idaho
Post Body

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!

Author
User Disabled User Suspended
Account Strength
0%
Disabled 9 months ago
Suspended 9 months ago
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
55
Link Karma
5,091
Comment Karma
27,325
Profile updated: 49 minutes ago
Posts updated: 10 months ago

Subreddit

Post Details

Location
We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago