我正在尝试在将某些对象添加到Realm时获取更新,使用通知块来执行更新。
@interface SessionManager ()
@property (strong, nonatomic) RLMResults<MetaAsset *> *metaAssets;
@property (strong, nonatomic) RLMNotificationToken *notificationToken;
@end
- (void)start
{
self.metaAssets = [[MetaAsset objectsWhere:@"isValid = YES"] sortedResultsUsingProperty:@"creationDate" ascending:NO];
self.notificationToken = [self.metaAssets addNotificationBlock:^(RLMResults<MetaAsset *> * _Nullable results, RLMCollectionChange * _Nullable change, NSError * _Nullable error) {
NSLog(@"received notification");
}];
[self addStuffToRealm];
}
我在- addStuffToRealm
中添加了一个断点,用于检查新MetaAsset
是否出现在self.metaAssets
中,并且它们是,但是从不调用通知块。也许我误解了通知块的作用?
谢谢!