SwiftData: NSCompoundPredicate predicateOperatorType: unrecognized selector sent to instance
Platform
iOS
Environment
Develop
Installed
Swift Package Manager
Version
8.18
Did it work on previous versions?
no
Steps to Reproduce
Use a SwiftData predicate that generates a ternary operator, in my case the code looks something like this
let kinds: [AwardKind] = [.firstTime, .nightOwl]
var descriptor = FetchDescriptor<Award>()
let rawKinds = kinds.map(\.rawValue)
descriptor.predicate = #Predicate<Award> { award in
if let rawKind = award.rawKind {
award.claimDate == nil && rawKinds.contains(rawKind)
} else {
award.claimDate == nil
}
}
Expected Result
Not crash
Actual Result
Crash in - (NSString *)comparisonPredicateDescription:(NSComparisonPredicate *)predicate because - (NSString *)predicateOperatorTypeDescription:(NSPredicateOperatorType)operator doesn't support TERNARY operator
Are you willing to submit a PR?
No response
Hey @sowenjub - I don't see a reason to believe this is caused by Sentry, can you explain? Did you try to reproduce without Sentry? To me it looks like the predicate and/or how it's used to query might be incorrect.
The query worked fine before I added Sentry, and still does if I don't init Sentry or if I disable Core Data tracing in the Sentry options.
The interruption points to Sentry code, the predicate generated by SwiftData includes a TERNARY operator which is not part of the supported operators in the function that crashes.
Ah yes you're right - we'll fix this, thanks for bringing it to our attention
Internal data points: https://sentry.sentry.io/issues/?project=4505469596663808&query=comparisonPredicateDescription&referrer=issue-list&statsPeriod=90d
I also have this issue using SwiftData and compound Predicates:
https://letsrodeo.sentry.io/issues/5092468581/?referrer=alert_email&alert_type=email&alert_timestamp=1711126918556&alert_rule_id=15065067¬ification_uuid=663b00cb-dd71-4ded-84cd-86543d085aec&environment=production
It works when sentry is removed