mei*_*sel 19 ios reactive-cocoa
如何从通知名称中创建信号?例如,我想从:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(userDidChange:)
name:kTTCurrentUserLoggedOffNotification
object:nil];
Run Code Online (Sandbox Code Playgroud)
类似于:
[signalForName(kTTCurrentUserLoggedOffNotification) subscribeNext:^(id x){
...
}];
Run Code Online (Sandbox Code Playgroud)
hfo*_*sli 46
-[NSNotificationCenter rac_addObserverForName:object:]返回无限信号.你可以像这样订阅它
Objective-C的
[[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIApplicationDidEnterBackgroundNotification object:nil]
takeUntil:[self rac_willDeallocSignal]]
subscribeNext:^(id x) {
NSLog(@"Notification received");
}];
Run Code Online (Sandbox Code Playgroud)
迅速
NSNotificationCenter.defaultCenter()
.rac_addObserverForName(UIKeyboardWillShowNotification, object: nil)
.takeUntil(self.rac_willDeallocSignal())
.subscribeNext { (_) in
print("Notification received")
}
Run Code Online (Sandbox Code Playgroud)
该信号如无限所述.如果您需要此信号/订阅绑定到寿命self,您可以添加takeUntil:使用rac_willDeallocSignal这样的:
Objective-C的
[[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIApplicationDidEnterBackgroundNotification object:nil]
takeUntil:[self rac_willDeallocSignal]]
subscribeNext:^(id x) {
NSLog(@"Notification received");
}];
Run Code Online (Sandbox Code Playgroud)
迅速
NSNotificationCenter.defaultCenter()
.rac_addObserverForName(UIKeyboardWillShowNotification, object: nil)
.takeUntil(self.rac_willDeallocSignal())
.subscribeNext { (_) in
print("Notification received")
}
Run Code Online (Sandbox Code Playgroud)
all*_*rog 10
在RACExtensions中,您可以找到该NSNotificationCenter (RACSupport)类别.这有一个方法:
- (RACSignal *)rac_addObserverForName:(NSString *)notificationName
object:(id)object;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8081 次 |
| 最近记录: |