I have a few that is passed an item of type FamilyMember. Available in the view is a list of Chores. A chore has a member assigned to it. I want to filter the chores to the passed family member.
2 Structures and view code:
@Model
class Chore: Identifiable {
@Attribute(.unique) var id = UUID()
var name: String
var frequency: ChoreFrequency
var assignedTo: FamilyMember
var isComplete: Bool
var dueDate: Date
init(id: UUID = UUID(), name: String = "", frequency: ChoreFrequency = .daily, assignedTo: FamilyMember = FamilyMember(), isComplete: Bool = false, dueDate: Date = Date()) {
self.name = name
self.frequency = frequency
self.assignedTo = assignedTo
self.isComplete = isComplete
self.dueDate = dueDate
}
}
@Model
class FamilyMember: Identifiable {
@Attribute(.unique) var id: String { name }
var name: String
init(name: String = "Unassigned") {
self.name = name
}
}
struct MemberView: View {
@Bindable var member: FamilyMember
@Query private var chores: [Chore]
init(member: FamilyMember) {
self.member = member
let predicate = #Predicate<Chore> {
$0.assignedTo == member // <— Error occurs here!
}
_chores = Query(filter: predicate, sort: \.dueDate)
}
.
.
.
It's when creating the predicate that I'm running to an error of value conversion.
Cannot convert value of type 'PredicateExpressions.Equal<PredicateExpressions.KeyPath<PredicateExpressions.Variable<Chore>, FamilyMember>, PredicateExpressions.Value<FamilyMember>>' to closure result type 'any StandardPredicateExpression<Bool>'
What am I doing wrong?