Cannot convert value of type 'PredicateExpressions.Equal<PredicateExpressions.KeyPath<PredicateExpressions.Variable<Quote>, UUID>, PredicateExpressions.KeyPath<PredicateExpressions.Value<Quote>, UUID>>' to closure result type 'any StandardPredicateExpression<Bool>'
에러가 발생하였습니다.
문제가 발생한 이유는 Predicate 내부에서 다른 모델 객체를 참조하는 것은 불가능하기 때문입니다.
위에 코드에서는 quote.id 를 통해서 quote 모델 객체의 id 를 참조하고 있으므로 문제가 발생합니다.
predicate: #Predicate { $0.id == quote.id }
그렇기 때문에 단순히 Predicate 외부에 참조할 객체의 변수를 담아 다음과 같이 문제를 해결할 수 있습니다.
As read here, you cannot reference a model object inside of a Predicate. So if you wanted to filter for a Usermodel, you could by using its id outside of the Predicate like such:
'SwiftUI > 에러해결' 카테고리의 다른 글
SwiftData - A default value requires a fully qualified domain named value, Model 프로퍼티에 Enum 사용하기 (0) | 2024.10.17 |
---|---|
SwiftUI - onChange 클로저 내부로 값 변경, 관찰 변경 안될 때 (0) | 2024.09.13 |
SwiftUI - MapUserLocationButton 작동 안될 때 (2) | 2024.09.10 |
SwiftUI - Sheet 내부에서 꾹 눌렀을 때만 동작, long press (0) | 2024.09.02 |
SwiftUI - Global functions are not supported in this predicate (SwiftData 에러) (0) | 2024.09.01 |