NSFetchRequest predicate querying correctly, but resulting NSManagedObject showing incorrect fields

31 views Asked by At

I'm have a Category entity in Core Data with a Boolean property, deleted. As an example, there are 3 saved with deleted set to false, 1 with true.

When I run a simple query:

let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "Category")
fetchRequest.predicate = NSPredicate(format: "deleted == %@", NSNumber(booleanLiteral: false))
let results = try managedContext.fetch(fetchRequest) as! [NSManagedObject]

it correctly returns the 3 with deleted set to false. If I invert the predicate, it correctly returns only the one with deleted set to true. So far, so good.

However, if instead I run it with NSPredicate(value: true) to get all stored Category entities, and then print the results, I see a deleted = 0 property for every result.

Clearly the actual database has 3 entities saved as false, one as true, since the queries are returning the expected objects. So what might the reason be for the returned results not displaying those fields correctly?

0

There are 0 answers