Realm Predicate for Membership in List

时间:2016-02-12 21:45:58

标签: ios swift nspredicate realm

I am trying to use RealmGridController to display elements in a relationship list. I have an object // remove the if from the while loop, as it really has no effect while ($row = $result->fetch_assoc()) { // you don't need the isset checks; if $row is set, then each value in it will be set $selectcomment2[] = 'same' . $row['cityID'] . $row['comment']); } // if there's nothing in the comments after the loop, then put 'different' in it if (!$selectcomment2) { $selectcomment2[] = 'different'; } that has a list of Collection:

Items

I would like to use a RealmGridController to show all of the items in the class Collection: Object { let items = List<Item>() dynamic var name: String? } class Item: Object { dynamic var name: String? } property of a specific items. RealmGridController uses RBQFetchedResultsController to manage its data loading, and the fetched results controller uses an entity name and a predicate to fetch the list of items to show.

How can I express the list of items in a relationship collection as an entity name and predicate?

A few things I've tried that haven't worked:

List

It seems like displaying a Realm 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) as the contents of a fetched results controller should be fairly straightforward but I just can't seem to figure it out. Thanks!

1 个答案:

答案 0 :(得分:1)

RBQFetchedResultsController不支持使用List作为数据源。我花了一些时间来研究如何使用KVO管理通知与RBQRealmNotificationManager,但从未完成。

目前,我建议查看Realm在v0.98.0中添加的新收集通知支持。您可以注册以在List中的任何对象更新时收到通知。这仍然没有提供索引更改信息,但这很快就会到来。