永远不会调用RLMResults通知块

时间:2016-08-10 02:12:05

标签: ios objective-c realm

我正在尝试在将某些对象添加到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中,并且它们是,但是从不调用通知块。也许我误解了通知块的作用?

谢谢!

0 个答案:

没有答案