Closed skalber-mm closed 8 months ago
Thank you for the report :)
It might be an issue with PersistentIdentifier
or NilLiteral
.
Can you provide a minimal reproducible example?
I am trying to reproduce the issue and am getting a SwiftData crash when trying to access nested relationships:
@Model
class PersonModel {
@Relationship
var partner: PersonModel?
}
let nestedRelationshipPredicate = #Predicate<PersonModel> { person in
person.partner?.partner?.persistentModelID == modelID
}
try context.fetch(.init(predicate: nestedRelationshipPredicate))
This seems to be an issue with SwiftData. I suggest trying to try unwrapping the optionals:
if let listing = contract.listing { ... } else { false }
I would welcome a minimal reproducible example as I am so far unable to reproduce this specific crash
Yes thanks, managed to solve it by reading this article: https://fatbobman.com/en/posts/how-to-handle-optional-values-in-swiftdata-predicates/
Happy to hear you could solve the issue. I'm closing it but marking it with FAQ for others with the same problem
I'm getting a crash with the following error:
It looks like the issue is in the
currentRoomPredicate
, if I remove it from theconjunction
array it doesn't crash:Is there a limit on the allowed nested objects in the predicate? I mean is the problem with
contract.listing?.room?.persistentModelID
?Thank you for the great work making this lib!