Store the rawValue in a variable and access the variable inside the #Predicate closure.
Given below is an example:
enum AccountType: Int, Codable, CaseIterable {
case creditAccountReceivable = 1,
creditAccountPayable = 2,
nominal = 3
}
@Model
class Account {
var type: Int
init(type: AccountType.RawValue) {
self.type = type
}
}
struct ContentView: View {
@Query
private var nominalAccounts: [Account]
init() {
//Store it in a variable type
let type = AccountType.creditAccountPayable.rawValue
let filter = #Predicate<Account> { account in
//Access the variable inside the closure
account.type == type
}
_nominalAccounts = Query(filter: filter, sort: \.type)
}
var body: some View {
Text("Hello")
}
}
Just a small suggestion, next time please post minimum code that would compile.
Add the tag SwiftData to the post so that experts in SwiftData can view your question as your question is more related to SwiftData
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: