ReactiveCocoa的用法

用户名和密码

RACSignal *usernameSignal = [self.phoneNumber.rac_textSignal
                                      map:^id(NSString *text) {
                                          return @(text.length > 3);
                                      }];
    RACSignal *passwordSignal = [self.code.rac_textSignal
                                      map:^id(NSString *text) {
                                          return @(text.length > 3);
                                      }];
    [[RACSignal combineLatest:@[usernameSignal, passwordSignal] reduce:^id(NSNumber *usernameValid, NSNumber *passwordValid) {
        return @([usernameValid boolValue] && [passwordValid boolValue]);
    }] subscribeNext:^(id x) {
          self.codeBtn.enabled = [x boolValue];
    }];

用户名, 密码, 其他

// 根据username password 和 是否同意
    RACSignal *usernameSignal = [self.phoneNumber.rac_textSignal
                                 map:^id(NSString *text) {
                                     return @([_viewModel isValidateMobile:text]);
                                 }];
    RACSignal *passwordSignal = [self.password.rac_textSignal
                                 map:^id(NSString *text) {
                                     return @(text.length > 5);
                                 }];
    
    RACSignal *agreeSignal = RACObserve(_viewModel, isAgree);
    [[RACSignal combineLatest:@[usernameSignal, passwordSignal,agreeSignal] reduce:^id(NSNumber *usernameValid, NSNumber *passwordValid, NSNumber *isAggree) {
        return @([usernameValid boolValue] && [passwordValid boolValue] && [isAggree boolValue]);
    }] subscribeNext:^(id x) {
        _confirmBtn.enabled = [x boolValue];
        self.confirmBtn.backgroundColor = [x boolValue] ? DBColorFromHex(0xfe2851) : DBColorFromHex(0xd8d8d8);
    }];

你可能感兴趣的:(ReactiveCocoa的用法)