Post

Replies

Boosts

Views

Activity

Cannot convert value of type to closure result type 'any StandardPredicateExpression<Bool>'
Hi, I have issue when I use swift data in development and I'm beginner. I have two basic classes. @Model class User{ @Attribute(.unique) var id: UUID; var account: String; var password: String; var name: String; var role: Role @Relationship(inverse: \Transaction.tranInitiator) var transcations = [Transaction]() init(account: String, password: String, name: String, role: Role) { self.id = UUID() self.account = account self.password = password self.name = name self.role = role } } // @Model class Transaction{ @Attribute(.unique) var tranId: UUID; var tranName: String; var tranCash: Float; var tranDate: Date; @Relationship var tranInitiator: User; // init block } } and when I am going to fetch items I use predictor like let predictor = #Predicate<Transaction>{ tran in tran.tranInitiator == user } fetchDescriptorTrans = FetchDescriptor(predicate: predictor) let transList = try? contextTransaction?.fetch(fetchDescriptorTrans) if(transList!.isEmpty){return []} else{ return transList! } compiler shows error Cannot convert value of type 'PredicateExpressions.Equal<PredicateExpressions.KeyPath<PredicateExpressions.Variable, User>, PredicateExpressions.Value>' to closure result type 'any StandardPredicateExpression' I don't know why
1
0
1.5k
Mar ’24