我的类别中有链接对象。
@property (readonly) RLMLinkingObjects *relatedAttachments;
我只想在有相关附件的情况下进行分类。我试试这个。
NSPredicate *pred = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"relatedAttachments.count > 0"]];
self.categories = [[Category objectsWithPredicate:pred] sortedResultsUsingProperty:@"id" ascending:YES];
我遇到这样的错误。
RLMPrecondition(property, @"Invalid property name",
所以我试试其他的。
NSPredicate *pred = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"relatedAttachments.count!=nil"]];
NSPredicate *pred = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"relatedAttachments.count!=NULL"]];
但是还是不行。我该怎么办?
最佳答案
您正在寻找像这样的谓词:
[NSPredicate predicateWithFormat:@"relatedAttachments.@count > 0"];
@count
是一个集合运算符,计算它出现在其右侧的集合中的元素数。
关于RLMLinkingObjects 的 iOS 谓词( Realm ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41604802/