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      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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.