我是新來的反應式編程,我在過濾和訪問特定索引中的對象時遇到困難。以下是我的代碼片段。無法使用RxSwift/RxRealm過濾對象
private var contacts: Observable<(AnyRealmCollection<Contact>, RealmChangeset?)>!
override func viewDidLoad() {
super.viewDidLoad()
contacts = Observable.changeset(from: contactViewModel.getDeviceContacts())
let dataSource = RxCollectionViewRealmDataSource<Contact>(cellIdentifier: "SendFeedContactCell", cellType: ContactCollectionCell.self) {cell, ip, contact in
cell.configure(contact)
}
contacts
.bindTo(collectionView.rx.realmChanges(dataSource))
.addDisposableTo(disposeBag)
searchBar
.rx.text
.orEmpty
.subscribe(onNext: { [unowned self] query in
// Filter query - doesn't work!
// self.contacts.filter({ (observable) -> Bool in
// observable.0.filter(NSPredicate(format: "name CONTAINS[c] '\(query)'"))
// })
})
.addDisposableTo(disposeBag)
collectionView.rx.itemSelected
.subscribe(onNext: { indexPath in
// TODO: How to access a specific object from the contacts object
})
.addDisposableTo(disposeBag)
}
我收到查詢的搜索欄,但過濾不似乎工作。
我在獲取IndexPath時收集視圖中選擇一個項目,但我想知道如何可以訪問基於索引路徑的特定模型屬性。
我使用RxRealm和RxRealmDataSources我的數據存儲在數據庫領域的設備。