Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Collection Changes Notifications #4

Closed
mbalex99 opened this issue Apr 22, 2016 · 1 comment
Closed

Support Collection Changes Notifications #4

mbalex99 opened this issue Apr 22, 2016 · 1 comment

Comments

@mbalex99
Copy link

After 3 years of poverty and dispair, Realm Finally added Collection Changes Notifications. Basically they can observe weather a collection has inserted, updated, changed, moved etc...

You can find more information here : https://realm.io/docs/swift/latest/#notifications

let myDog = Dog()
        myDog.name = "Rex"
        myDog.age = 1

        realm.add(myDog)


       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.insertRowsAtIndexPaths(insertions.map { NSIndexPath(forRow: $0, inSection: 0) },
          withRowAnimation: .Automatic)
        tableView.deleteRowsAtIndexPaths(deletions.map { NSIndexPath(forRow: $0, inSection: 0) },
          withRowAnimation: .Automatic)
        tableView.reloadRowsAtIndexPaths(modifications.map { NSIndexPath(forRow: $0, inSection: 0) },
          withRowAnimation: .Automatic)
        tableView.endUpdates()
        break
      case .Error(let error):
        // An error occurred while opening the Realm file on the background worker thread
        fatalError("\(error)")
        break
      }
    }
@icanzilb
Copy link
Member

Please keep neutral tone when reporting bugs or issues. Fine grained notifications have been added in 0.1.3: https://github.com/RxSwiftCommunity/RxRealm/releases/tag/0.1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants