horseshoe7
horseshoe7

Reputation: 2837

Core Data - Fetch Request results not matching the predicate

I'm pretty confused as to why the following is not working:

enter image description here

As you can see in the debug console, the value for newerContentAvailable is 0 even though I only want objects who have this value set to 1. But it made its way into the results anyway.

Yes, I'm using MagicalRecord, but doubtful this has anything to do with it. It's an old, mature codebase and MR_findAllWithPredicate:... just creates a fetch request on that data model and sets the predicate of the fetch.

Is there something I've not understood about Core Data? I admit it is a beast of a framework and best practices are scarce.

Would be seriously grateful for some help!

Upvotes: 1

Views: 255

Answers (2)

pbasdf
pbasdf

Reputation: 21536

I believe the problem may be a result of the attribute name you have used: names beginning with new... seem to cause some unexpected behaviour (*). Try changing the attribute name to see if that sorts it.

(*) See for example this question and answer.

Upvotes: 1

kgkoutio
kgkoutio

Reputation: 89

NSNumber value of NSNumber is not substituted when used with %@ format. You have to get the intValue or floatValue (doubleValue etc) which returns the correct type.

The predicate should be,

NSPredicate *findPred = [NSPredicate predicateWithFormat:@"newerContentAvailable == 1"];

OR

NSNumber *number = @1; //Or any other number
NSPredicate *findPred = [NSPredicate predicateWithFormat:@"newerContentAvailable == %d", [number intValue]];

Upvotes: 0

Related Questions