0

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?

Naftali Beder
  • 1,066
  • 1
  • 10
  • 27
  • Please show the code that displays the results as well as a sample of the resulting output. I suspect you are running into a faulting problem but want to see the code to confirm. – Marcus S. Zarra Dec 20 '16 at 18:55
  • 2
    You should not name a Core Data attribute "deleted", compare http://stackoverflow.com/questions/16000242/core-data-nspredicate-predicatewithblock-and-predicatewithformat-in-parent-child. – Martin R Dec 20 '16 at 19:31
  • @MartinR That's it, interesting. I marked this as a duplicate of the link you posted, but it might warrant its own answer, so feel free to post it and I'll mark it correct. – Naftali Beder Dec 20 '16 at 20:10

0 Answers0