I'm running into an error in Xcode 16 beta 4 where the compiler can't type check what appears to be a simple @FetchRequest.
I have the following Core Data types:
Establishment
- name
- website
- etc.
- locations (relationship, to many, optional)
Location
- name
- address
- establishment (relationship, to one, non-optional)
In one of my SwiftUI views I have the following @FetchRequest and SortDescriptors. Unwrap required because 'core data' optional types. It looks based on the swift lang key-path expression docs that this should be allowed. Build and run works, but archiving does not. https://docs.swift.org/swift-book/documentation/the-swift-programming-language/expressions/#Key-Path-Expression
In practice it won't be nil and validation should prevent it too so I could force unwrap the relationship property, but, defensive coding I want to make it safe as I can.
@FetchRequest(
sortDescriptors: [
SortDescriptor(\Location.establishment?.name, order: .forward),
SortDescriptor(\Location.city, order: .forward),
SortDescriptor(\Location.state, order: .forward)
]
)
private var locations: FetchedResults<Location>
This worked fine with Xcode 15.x, but fails to archive in Xcode 16 beta 4.
The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
When I remove the first sort descriptor it works. When I force unwrap the optional key path property it works.
Does anyone know of a documented change that would make this no longer work?
FB14515958 - SwiftUI: SortDescriptor cannot archive in Xcode 16 beta 4 but works in Xcode 15.4
For clarity, this archives fine, note the force unwrap.
@FetchRequest(
sortDescriptors: [
SortDescriptor(\CraftTaproom.brewery!.name, order: .forward),
SortDescriptor(\CraftTaproom.city, order: .forward),
SortDescriptor(\CraftTaproom.state, order: .forward)
]
)
private var taprooms: FetchedResults<CraftTaproom>