RLMLinkingObjects 的 iOS 谓词( Realm )

标签 ios realm

我的类别中有链接对象。

@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/

相关文章:

ios - 更改iOS 7中的引用计数?

ios - UICollectionView 未显示 - 错误?

ios - Swift - 获取下一个日期

java - 按整数过滤 Realm 结果

arrays - Swift 库中的数组问题 - Realm 2.4.1

android - Android : Correct structure or not? 中具有单例模式的 Realm

ios - UILabel 使用 NSTimer 更新不正确

ios - 插值和预测 CLLocationManager

ios - JSON 到 Realm 对象映射问题 iOS Swift

java - 如何在现有 Realm 数据库中添加新表?