WWDC23 SALE: Save 50% on all my Swift books and bundles! >>

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")
                            }// END OF NAV LINK
                        }// END OF FOR EACH
                        .onDelete(perform: deleteProducts)
                    }// END OF LIST
                    .frame(height: geometry.size.height * 0.62)


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


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.


Save 50% in my WWDC23 sale.

SAVE 50% To celebrate WWDC23, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.