5-3-2RAC-使用信号创建登录注册逻辑(传统的思维逻辑)

登录界面xib设置

111.png
#import "ViewController.h"
#import 
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *accountField;
@property (weak, nonatomic) IBOutlet UITextField *passwordField;
@property (weak, nonatomic) IBOutlet UIButton *LoginButton;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    //处理文本框业务逻辑
  RACSignal *loginEnableSignal = [RACSignal combineLatest:@[_accountField.rac_textSignal,_passwordField.rac_textSignal] reduce:^id _Nonnull (NSString *account,NSString *pwd){
        return @(account.length&&pwd.length);
    }];
    //设置按钮
    RAC(_LoginButton,enabled) = loginEnableSignal;
    
    //创建命令
    RACCommand *command = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        //处理事件密码加密
        NSLog(@"准备发送请求");
        NSLog(@"拿到%@",input);
        
        return [RACSignal createSignal:^RACDisposable * _Nullable(id  _Nonnull subscriber) {
            //发送请求&&获取登录结果!!
            [subscriber sendNext:@"请求登录数据"];
            [subscriber sendCompleted];
                return nil;
        }];
    }];
    //获取命令中信号源
    [command.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    //监听命令执行过程!!
    [command.executing /*skip:1] */subscribeNext:^(NSNumber * _Nullable x) {
        NSLog(@"%@",x);
        if ([x boolValue]) {
            NSLog(@"显示菊花");
        }else{
            NSLog(@"干掉菊花");
        }
    }];
    //监听按钮的点击
    [[_LoginButton rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
        NSLog(@"点击了登录按钮");
        //处理登录事件
        [command execute:@"账号密码"];
        //qqq
    }];
}

你可能感兴趣的:(5-3-2RAC-使用信号创建登录注册逻辑(传统的思维逻辑))