I have a Core Data model with a one-to-many relationship e.g.:
@interface Person : NSManagedObect
@property (nonatomic, retain) NSSet *children;
@end
I want to create a predicate which only gives me the Person
s that have at least one child:
I tried:
[NSPredicate predicateWithFormat:@"person.children.count > 0"]
But I get NSPredicate to-many key not allowed
.
Ok, I found some documentation on the realm.io site about NSPredicate
collection queries which has the answer:
You have to use @count
instead of just count
:
So: [NSPredicate predicateWithFormat:@"person.children.@count > 0"]
Pity that Apple doesn't document this themselves (at least not that I could find).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With