2016-11-20 7 views
0

オブジェクト私は、親オブジェクトのプロパティが割り当てられたときに通知を受信すると、通知の結果を持っている。ここ1.0.2通知が

をchaangedすべての子供が含まれているコードの行は、私が参照してるです:

realm.objects(Parent.self).filter("state = Error").addNotificationBlock { ... } 

現在、私は通知を受け取りますが、どのオブジェクトに適用されるかはわかりません。これは可能ですか、それともそれぞれを通過する必要がありますか?

ありがとう、 マイク。

答えて

0

Realm WebサイトのCollection Notificationsに関するドキュメントによれば、Resultsオブジェクトをクエリから取り出して、通知ブロックを割り当てることができます。その結果セット(新しい追加、変更、削除を含む)でオブジェクトが変更されると、ブロックは変更された特定のインデックスでトリガーされます。

// Observe Results Notifications 
notificationToken = results.addNotificationBlock { [weak self] (changes: RealmCollectionChange) in 
    guard let tableView = self?.tableView else { return } 
    switch changes { 
    case .initial: 
    // Results are now populated and can be accessed without blocking the UI 
    tableView.reloadData() 
    break 
    case .update(_, let deletions, let insertions, let modifications): 
    // Query results have changed, so apply them to the UITableView 
    tableView.beginUpdates() 
    tableView.insertRows(at: insertions.map({ IndexPath(row: $0, section: 0) }), with: .automatic) 
    tableView.deleteRows(at: deletions.map({ IndexPath(row: $0, section: 0)}), with: .automatic) 
    tableView.reloadRows(at: modifications.map({ IndexPath(row: $0, section: 0) }), with: .automatic) 
    tableView.endUpdates() 
    break 
    case .error(let error): 
    // An error occurred while opening the Realm file on the background worker thread 
    fatalError("\(error)") 
    break 
    } 
} 

ここで子供たちが何を意味しているのか分かりません。つまり、ParentオブジェクトにListプロパティがある場合は、Parentオブジェクトのどの子オブジェクトが変更されたかに関する細かいインデックス情報は得られませんが、子オブジェクトが属するParentオブジェクト自体のインデックスは引き続き取得されます。

関連する問題