RAC

2020-06-22  本文已影响0人  xiari1991
//监听,不需dealloc移除
[RACObserve(self, name) subscribeNext:^(id  _Nullable x) {
    NSLog(@"%@",x);
}];

[self.textField.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
    NSLog(@"%@",x);
}];


self.btn.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        NSLog(@"%@", click);
        return [RACSignal empty];
    }];
或者
[[btn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        NSLog(@"点我了");
    }];

//接收通知,不需dealloc移除
[[[NSNotificationCenter defaultCenter]rac_addObserverForName:@"RACNotification" object:nil]subscribeNext:^(id x) {
        
        NSLog(@"%@",x);
        
    }];

//cell中的btn,需要用到takeUntil
[[[btn rac_signalForControlEvents:UIControlEventTouchUpInside]takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(__kindof UIControl * _Nullable x) {
        NSLog(@"点我了");
    }]];


self.command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"RACNotification" object:@[@"rac  change"]];
        return [RACSignal empty];
    }];
[self.command execute:@"111"];//手动触发。

 //合并两个输入框的信号量,并使用map对信号量返回值进行映射使其返回bool值
    self.loginParamBigSignal = [[RACSignal combineLatest:@[RACObserve(self, phoneStr),RACObserve(self, SMSCodeStr)]] map:^id _Nullable(RACTuple * _Nullable value) {
        RACTupleUnpack(NSString *phone , NSString *SMSCode) = value;
        //@()将值变量装箱成对象
        return @([phone length]>0 && [SMSCode length]>0);
    }];
上一篇下一篇

猜你喜欢

热点阅读