After updating Xcode to version 16, all functions that I used to create FetchDescriptor return with a warning:
Type 'ReferenceWritableKeyPath<Station, Optional>' does not conform to the 'Sendable' protocol; this is an error in the Swift 6 language mode
Minimum example:
@Model public class Station {
var stationKey: Int16? = 0
}
extension Station {
static func allFD()->FetchDescriptor<Station> {
let predicate = #Predicate<Station> {value in
true
}
let descriptor=FetchDescriptor<Station>(predicate: predicate, sortBy: [SortDescriptor(\Station.stationKey)])
return descriptor
}
The idea to have "FetchDescriptors" defined in an extension was to be able to use them both in Views and "background" code.
But now I am not sure how to proceed if I want to sort as well.
Thank you for your comments and ideas.
This is something that will be fixed so that the compiler will treat key paths as sendable but until then you can silence the warning in Xcode by setting Infer Sendable for Methods and Key Path Literals to Yes
in the build settings (search for sendable) for your project/target or if you are using a package then add
.enableUpcomingFeature("InferSendableFromCaptures")
See this discussion or the proposal 418