0

This seems to be the same as How to use binary flags in Core Data? but I am getting an "Unsupported function expression" when trying.

I want to create a predicate that can find entities in my Core Data object store which have a certain ID and for which certain binary flags are not set. This is my code snippet:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ownerID = %@ AND ((banned & 8) == 0)", THEUSERUSERID];
NSFetchRequest *fetchRequest = [PCDUser MR_requestAllWithPredicate:predicate];

_frController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[[COMMDBMANAGER magicalRecordStack] context] sectionNameKeyPath:sectionKeyPath cacheName:nil];

[_frController setDelegate:self];
[_frController performFetch:&error];

Looking at the previous issue in the link above, it appears this should work. However, I get a

'NSInvalidArgumentException', reason: 'Unsupported function expression banned & 8'

Because I need the NSFetchedResultsController results set (and indexPaths etc) to include the filtered results, I have not been able to find a way to filter them after the fact and have the results set include that filtering.

How does one use binary flags in Core Data?

Community
  • 1
  • 1
chadbag
  • 1,837
  • 2
  • 20
  • 34
  • I had a similar predicate in `NSFetchRequest` and it worked. Are you sure that property `banned` exists and has a type that supports bitwise operations (for example, `Integer32`)? – Michał Ciuba Dec 08 '14 at 22:04
  • Thank you. I had been helping a node.js guy on the backend mysql database that supports this app (and which this CD store in the DB derives data from) and I had in my head the wrong name for the property. In the CD schema I have `bannedFlags` but in mysql `banned` [don't ask why as I don't know] and after a long long weekend of dealing with `banned` I had a brain fart this morning. Thanks for the reminder to double check the obvious. Make an answer and I will accept it. – chadbag Dec 08 '14 at 22:16

1 Answers1

4

I had a similar predicate in NSFetchRequest and it worked. Check that property banned exists in your model and has a type that supports bitwise operations (for example, Integer32).

Michał Ciuba
  • 7,876
  • 2
  • 33
  • 59