列表中成员资格的领域谓词
Realm Predicate for Membership in List
我正在尝试使用 RealmGridController 来显示关系列表中的元素。我有一个对象 Collection
,它有一个列表 Items
:
class Collection: Object {
let items = List<Item>()
dynamic var name: String?
}
class Item: Object {
dynamic var name: String?
}
我想使用 RealmGridController 来显示特定 collection
的 items
属性 中的所有项目。 RealmGridController 使用 RBQFetchedResultsController 来管理其数据加载,获取的结果控制器使用实体名称和谓词来获取要显示的项目列表。
如何将关系 List
中的项目列表表示为实体名称和谓词?
一些我尝试过但没有奏效的方法:
entityName = Item.className()
// 'Invalid predicate', reason: 'Predicate with IN operator must compare a KeyPath with an aggregate'
basePredicate = NSPredicate(format: "SELF in %@.items", collection)
// Same
basePredicate = NSPredicate(format: "SELF in %@", collection.items)
// 'Invalid predicate', reason: 'Predicate with ANY modifier must compare a KeyPath with RLMArray with a value'
basePredicate = NSPredicate(format: "ANY SELF in %@", collection.items)
似乎显示 Realm List<>
作为获取结果控制器的内容应该相当简单,但我似乎无法弄清楚。谢谢!
RBQFetchedResultsController
不支持使用 List
作为数据源。我花了一些时间来探索使用 KVO 管理通知与 RBQRealmNotificationManager
但从未完成。
现在,我建议研究 v0.98.0 中添加的 Realm 新的集合通知支持。您可以注册以在 List
中的任何对象更新时接收通知。这仍然不提供索引更改信息,但很快就会提供。
我正在尝试使用 RealmGridController 来显示关系列表中的元素。我有一个对象 Collection
,它有一个列表 Items
:
class Collection: Object {
let items = List<Item>()
dynamic var name: String?
}
class Item: Object {
dynamic var name: String?
}
我想使用 RealmGridController 来显示特定 collection
的 items
属性 中的所有项目。 RealmGridController 使用 RBQFetchedResultsController 来管理其数据加载,获取的结果控制器使用实体名称和谓词来获取要显示的项目列表。
如何将关系 List
中的项目列表表示为实体名称和谓词?
一些我尝试过但没有奏效的方法:
entityName = Item.className()
// 'Invalid predicate', reason: 'Predicate with IN operator must compare a KeyPath with an aggregate'
basePredicate = NSPredicate(format: "SELF in %@.items", collection)
// Same
basePredicate = NSPredicate(format: "SELF in %@", collection.items)
// 'Invalid predicate', reason: 'Predicate with ANY modifier must compare a KeyPath with RLMArray with a value'
basePredicate = NSPredicate(format: "ANY SELF in %@", collection.items)
似乎显示 Realm List<>
作为获取结果控制器的内容应该相当简单,但我似乎无法弄清楚。谢谢!
RBQFetchedResultsController
不支持使用 List
作为数据源。我花了一些时间来探索使用 KVO 管理通知与 RBQRealmNotificationManager
但从未完成。
现在,我建议研究 v0.98.0 中添加的 Realm 新的集合通知支持。您可以注册以在 List
中的任何对象更新时接收通知。这仍然不提供索引更改信息,但很快就会提供。