美文网首页
ReactiveCocoa中通知的正确使用

ReactiveCocoa中通知的正确使用

作者: tljackyi | 来源:发表于2016-07-16 21:02 被阅读1825次

在iOS我们都知道注册完通知后,都要移除通知,配对使用。

那在ReactiveCocoa中如何正确的使用通知,我们可以通过RAC()-takeUntil:达到结束消息,移除通知。

// Stops observing the notification when `self` is deallocated.
RAC(self.latestObject) = [[NSNotificationCenter.defaultCenter
    rac_addObserverForName:GimmeDatObjectNotification object:nil]
    map:^(NSNotification *notification) {
        return notification.userInfo[DatObjectKey];
    }];

// Stops observing the notification when `cancelSignal` sends next or completed.
[[[NSNotificationCenter.defaultCenter
    rac_addObserverForName:SomeNotification object:nil]
    takeUntil:cancelSignal]
    subscribeNext:^(id x) {
        @strongify(self);
        NSLog(@"UPDATE UPDATE");
    }];

相关文章

网友评论

      本文标题:ReactiveCocoa中通知的正确使用

      本文链接:https://www.haomeiwen.com/subject/anyujttx.html