0

I have a fairly simple Categories class shown at the bottom of the post. keyValue is a UUID value, but this predicate is failing.

let keyPredicate = #Predicate<Categories> { $0.uuidKey == keyValue }

When I use it in a fetch request I get the very uninformative error The operation couldn’t be completed. (SwiftData.SwiftDataError error 1.).

Fetching var keyDescriptor = FetchDescriptor<Categories>() returns a nice array.

let test = try modelContext.fetch(keyDescriptor)
let filterTest = test.filter { 
    $0.uuidKey == keyValue
}

filterTest returns a very nice filtered array with one Categories instance as I expect. Any suggestions why the #Predicate doesn't work aside from this being beta software?

@Model
class Categories: Identifiable {
    
    // MARK: Identifiable
    var id: UUID { return uuidKey }
    
     // MARK: - Properties
    @Attribute(.unique) var uuidKey: UUID = UUID()
    // var uuidKey: UUID = UUID()
    var dateCreated: Date = Date()
    var dateModified: Date = Date()
    var dateRealm: Date? = nil
    var uuidUser: UUID = UUID()
    var uuidFamily: UUID = UUID()
    var myName: String = ""
}

Xcode Version 15.0 beta (15A5160n)

HangarRash
  • 7,314
  • 5
  • 5
  • 32
adamek
  • 2,324
  • 3
  • 24
  • 38

0 Answers0