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?
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
).