NFC.cool
NFC.cool

Reputation: 3312

CoreData fetch request NSPredicate not working

I've added a new bool property to an entity in my CoreData model and migrated the existing data to the new model. I now want to fetch only the data with a bool value of false. I tried everything suggested here on StackOverflow but I could not find an answer to my problem.

I tried following predicates:

let predicate = NSPredicate(format: "%K == %i", #keyPath(Tag.isWrite), false)
fetchRequest.predicate = predicate
let predicate = NSPredicate(format: "isWrite == 0")
fetchRequest.predicate = predicate
let predicate = NSPredicate(format: "isWrite == %@", NSNumber(value: false))
fetchRequest.predicate = predicate

The default value for the migrated model is false for isWrite. When I don't apply the predicate and set a breakpoint before displaying my data I can clearly see that isWrite is false in the debugger. When I apply the predicate I don't get any data.

Am I missing something out?

Upvotes: 1

Views: 298

Answers (1)

pbasdf
pbasdf

Reputation: 21536

There appears to be a problem in CoreData with attribute names beginning with “is...”. Try changing the name for your attribute.

Upvotes: 3

Related Questions