UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

CoreData Sort Descriptor Not Working

Forums > SwiftUI

Hi I am using CoreData to populate a list of products. I want the list to be sorted by "make" + then "model". Seems simple but for some reason the list does not get sorted. Any Ideas What The Issue Is??

My Fetch Request Is... @FetchRequest(sortDescriptors: [ SortDescriptor(\.make), SortDescriptor(\.model) ]) var products: FetchedResults<Product>

My List Is...

`List { ForEach(products, id: .self) { product in

                            NavigationLink(destination: ProductDetailView(product: product)) {
                                HStack {
                                    Text(product.make ?? "Unknown")
                                    Text(product.model ?? "Unknown")
                                    Text(String(product.tileWidth))
                                }
                            }// END OF NAV LINK
                        }// END OF FOR EACH
                        .onDelete(perform: deleteProducts)
                    }// END OF LIST
                    .frame(height: geometry.size.height * 0.62)
                    .listStyle(InsetGroupedListStyle())`

2      

Could you give an example what do you get and what do you expect? Are the data types in make and model correct?

2      

Hi make + model are both Strings.

I would expect to get... Ford Escort Ford Sierra Nissan Micra VW Golf

Instead I just get a random order.

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.