How can I filter an item based on an array using a Predicate
I am having the following SwiftData models:
@Model
class Place {
...
@Relationship(inverse: \Tag.places) var tags: [Tag]
...
}
and
@Model
class Tag {
...
@Attribute(.unique) var uuid: UUID
@Relationship(deleteRule: .nullify) private(set) var places: [Place]
...
}
I want to filter the Place model based on its tags to match against any provided tags
for example I want all places that have any of [work, restaurants] tags
what I did is:
let tags: [Tag] = ...
#Predicate<Place> { place in
place.tags.allSatisfy { tag in
tags.contains(where: { $0.uuid == tag.uuid })
}
}
I am getting this error:
Cannot convert value of type 'PredicateExpressions.SequenceAllSatisfy<PredicateExpressions.KeyPath<PredicateExpressions.Variable, [Tag]>, PredicateExpressions.SequenceContainsWhere<PredicateExpressions.Value<[Tag]>, PredicateExpressions.Equal<PredicateExpressions.KeyPath<PredicateExpressions.Variable, UUID>, PredicateExpressions.KeyPath<PredicateExpressions.Variable, UUID>>>>' to closure result type 'any StandardPredicateExpression'
Any thoughts on how can I make it work?