SwiftData crash when using a @Query sort descriptor with a relationship

I am using SwiftData for storage and have a view that uses the @Query property wrapper with a sort descriptor that points to a relationship on a model. In a release build on device running iOS 18.3, the app crashes.

This is the line that crashes:

@Query(sort: \Item.info.endDate, order: .reverse) private var items: [Item]

Item has a relationship to ItemInfo, which is where the endDate property is defined. This code works in debug and on a simulator.

In the project referenced here: https://github.com/lepolt/swiftdata-crash, change the scheme build configuration to “Release” and run on device. The app will crash.

Using Xcode Version 16.2 (16C5032a) iPhone 12, iOS 18.3 (22D60)

This looks like a regression on iOS 18.3, as the same code works well on iOS 18.2.1. I've filed a feedback report (r.143721511) to track the issue.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

@DTS Engineer Any recommendations for this behavior? Working with @Query and @Relationship is a standard practice with SwiftData, but we are going to face live issues without support from Apple on this regression as adoption grows rapidly.

Running into similar issue here. Adding error from console so other devs can find this when searching.

SwiftData/Schema.swift:305: Fatal error: KeyPath \Caliber.<computed 0x000000010273b228 (Manufacturer)>.<computed 0x000000010273b230 (String)> points to a field (<computed 0x000000010273b228 (Manufacturer)>) that is unknown to Caliber and cannot be used.

From my investigation sort descriptor pointing to a relationship on a model is to blame (doesn't have to be @Query property wrapper, also used in FetchDescriptor crashes).

Possible workaround - copy property from relationship to model and sort by it.

Still not fixed in 18.3.1

Can concur that I'm having the same issue- a @Query sort descriptor is causing my app to crash on launch, and the issue only began on iOS 18.3.

Frustratingly enough, it doesn't happen when I build and install the app through Xcode, even on a Release configuration.

I thought that it was fixed by just recompiling with a newer version of Xcode (I had built and submitted my app a few months ago) and it even passed the app store review, so I guess they're not using the latest version of iOS??

I'm very frustrated by this regression- I have a big marketing push scheduled for my app and this is the absolute worst timing for such an issue to come up. Now I have to wrangle with manually archiving and sideloading my app just to test whether a fix is working. Frankly, iOS 18's entire release cycle has just been a disaster. One of the buggiest things I've ever had the displeasure to deal with. Feels like this isn't the same Apple- even 2 years ago it feels like they'd never let such a buggy release like this happen.

SwiftData crash when using a @Query sort descriptor with a relationship
 
 
Q