2016-02-12 62 views
0

我試圖使用RealmGridController來顯示關係列表中的元素。我有一個對象Collection擁有的Items列表:列表成員列表中的領域謂詞

class Collection: Object { 
    let items = List<Item>() 

    dynamic var name: String? 
} 

class Item: Object { 
    dynamic var name: String? 
} 

我想用一個RealmGridController顯示所有的項目在一個特定的collectionitems財產。 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) 

這似乎是顯示領域List<>爲獲取結果控制器的內容應該是相當簡單,但我做不到似乎弄明白了。謝謝!

回答

1

RBQFetchedResultsController不支持使用List作爲數據源。我花了一些時間研究這個問題,以探索使用KVO來管理通知與RBQRealmNotificationManager,但從未完成它。

現在,我建議您考慮在v0.98.0中添加Realm的新收藏通知支持。您可以註冊以在List中的任何對象更新時收到通知。這仍然沒有提供指數變化信息,但即將推出。