Reputation: 165
I am playing around with swift and realm in an IOS app.
I try to reload tableView by using realm.addNotificationBlock. But I don't know how to implement this. Can someone help me with exact code example?
Thanks
Upvotes: 1
Views: 4035
Reputation: 451
If you are using addNotificationBlock, The naming of addNotificationBlock: does not seem to be very consistent with the latest Swift naming conventions So you please use this code
notificationToken = realm.observe { (notification, realm) in
}
Upvotes: 0
Reputation: 11683
You can check the class reference to implement the notification handler that catch the changes in the RLMRealm: http://realm.io/docs/cocoa/0.80.0/api/Classes/RLMRealm.html
In this issue you have a test case (non main thread) using the addNotificationBlock.
I hope this may help you.
Check also the examples: RealmTableViewExample
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupUI];
// Set realm notification block
__weak typeof(self) weakSelf = self;
self.notification = [RLMRealm.defaultRealm addNotificationBlock:^(NSString *note, RLMRealm *realm) {
[weakSelf reloadData];
}];
[self reloadData];
}
- (void)reloadData
{
self.array = [[DemoObject allObjects] arraySortedByProperty:@"date" ascending:YES];
[self.tableView reloadData];
}
Upvotes: 4