Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There is no method addNotificationBlock in Realm. Where is it?

I'm trying to use .addNotificationBlock method in Swift Realm. I have other methods but not actually this one (look at the image). Why?

let realm = RealmService.shared.realm
racks = realm.objects(Rack.self)

notificationToken = realm.??? { (notification, realm) in
    self.tableView.reloadData()

enter image description here

like image 895
Tim Avatar asked Dec 24 '22 04:12

Tim


2 Answers

3.0.0 Release notes (2017-10-16)

Breaking Changes

Old API New API

NotificationToken.stop() NotificationToken.invalidate()

-[RLMNotificationToken stop] -[RLMNotificationToken invalidate]

RealmCollection.addNotificationBlock(:) RealmCollection.observe(:)

Try observe?

like image 171
EpicPandaForce Avatar answered Dec 25 '22 16:12

EpicPandaForce


Swift 5

//Refresh the tableView in Real time returning a notification token
        notificationToken = realm.observe { (notification, realm) in
            self.tableView.reloadData()
        }

        notificationToken.invalidate() // instead of stop()

like image 36
Marlhex Avatar answered Dec 25 '22 17:12

Marlhex