Enums
The following enums are available globally.
-
A
RealmCollectionChange
value encapsulates information about changes to collections that are reported by Realm notifications.The change information is available in two formats: a simple array of row indices in the collection for each type of change, and an array of index paths in a requested section suitable for passing directly to
UITableView
‘s batch update methods.The arrays of indices in the
.update
case followUITableView
’s batching conventions, and can be passed as-is to a table view’s batch update functions after being converted to index paths. For example, for a simple one-section table view, you can do the following:
See moreself.notificationToken = results.addNotificationBlock { changes in switch changes { case .initial: // Results are now populated and can be accessed without blocking the UI self.tableView.reloadData() break case .update(_, let deletions, let insertions, let modifications): // Query results have changed, so apply them to the TableView self.tableView.beginUpdates() self.tableView.insertRows(at: insertions.map { IndexPath(row: $0, section: 0) }, with: .automatic) self.tableView.deleteRows(at: deletions.map { IndexPath(row: $0, section: 0) }, with: .automatic) self.tableView.reloadRows(at: modifications.map { IndexPath(row: $0, section: 0) }, with: .automatic) self.tableView.endUpdates() break case .error(let err): // An error occurred while opening the Realm file on the background worker thread fatalError("\(err)") break } }
Declaration
Swift
public enum RealmCollectionChange<T>