I have linking object in my category.
@property (readonly) RLMLinkingObjects *relatedAttachments;
I only want to take category if it have relatedAttachments. I try with this.
NSPredicate *pred = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"relatedAttachments.count > 0"]];
self.categories = [[Category objectsWithPredicate:pred] sortedResultsUsingProperty:@"id" ascending:YES];
I got error like this.
RLMPrecondition(property, @"Invalid property name",
So I try with other.
NSPredicate *pred = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"relatedAttachments.count!=nil"]];
NSPredicate *pred = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"relatedAttachments.count!=NULL"]];
But it is still not okay. How shall I do?
You're looking for a predicate like:
[NSPredicate predicateWithFormat:@"relatedAttachments.@count > 0"];
@count
is a collection operator that evaluates to the number of elements in the collection it appears to the right of.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.