ReactiveCocoa中通知的正确使用

在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");
    }];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容