Hi,
I have the following predicate used in a SwiftData Query:
#Predicate<Item> {
searchText.isEmpty || $0.myarray.contains(where: {
$0.text.localizedStandardContains(searchText)
})
})
Even though this compiles, I get the unsupportedKeyPath error in the logs:
Query encountered an error: SwiftData.SwiftDataError(_error: SwiftData.SwiftDataError._Error.unsupportedKeyPath)
I thought I could use .contains(where:)
inside predicates, but this doesn't work. What could be the problem?
Item.myarray
is an array of a Codable struct type, and searchText is a String
.
I'm not exactly sure if this is the same issue, but from what I understand, collections, enums and other non-trivial value types are stored as binary data in CloudKit (you can check in CloudKit console) and their contents therefore can't be queried with a predicate.
It's also mentioned here: https://www.hackingwithswift.com/quick-start/swiftdata/using-structs-and-enums-in-swiftdata-models