在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");
}];
网友评论