-[NSNotificationCenter rac_addObserverForName:object:]
返回一个无限信号。你可以像这样订阅它
目标-c
[[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIApplicationDidEnterBackgroundNotification object:nil]
takeUntil:[self rac_willDeallocSignal]]
subscribeNext:^(id x) {
NSLog(@"Notification received");
}];
迅速
NSNotificationCenter.defaultCenter()
.rac_addObserverForName(UIKeyboardWillShowNotification, object: nil)
.takeUntil(self.rac_willDeallocSignal())
.subscribeNext { (_) in
print("Notification received")
}
该信号如上所述是无限的。如果您需要将此信号/订阅绑定到您的生命周期,可以self
像这样添加:takeUntil:
rac_willDeallocSignal
目标-c
[[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIApplicationDidEnterBackgroundNotification object:nil]
takeUntil:[self rac_willDeallocSignal]]
subscribeNext:^(id x) {
NSLog(@"Notification received");
}];
迅速
NSNotificationCenter.defaultCenter()
.rac_addObserverForName(UIKeyboardWillShowNotification, object: nil)
.takeUntil(self.rac_willDeallocSignal())
.subscribeNext { (_) in
print("Notification received")
}