美文网首页
RAC初学记录

RAC初学记录

作者: JaniceCoder | 来源:发表于2018-04-24 16:01 被阅读13次

个人记录,方便查阅

场景 1.    用户登录,登录按钮需账号密码同时满足某个条件才能点击

NSArray *signals = @[self.phoneTextField.rac_textSignal, self.passwordTextField.rac_textSignal];

RAC(self.loginButton, enabled) = [RACSignal combineLatest:signals reduce:^(NSString *username, NSString *password) {

    return@(username.length > 0 && password.length >= 6);

}];

场景 2. 登录密码框右边按钮,点击可查看密码,再次点击变为******

@weakify(self);

    [[[self.securityButton rac_signalForControlEvents:UIControlEventTouchUpInside] map:^id(UIButton *button) {

        button.selected =  !button.selected;

        return @(button.selected);

    }] subscribeNext:^(idx) {

        @strongify(self);

        self.passwordTextField.secureTextEntry =  ![xboolValue];

    }];

场景 3. 获取验证码60S倒计时,倒计时期间按钮为不可点状态

```

- (RACSignal *)resendVerificationCode {

    staticconstNSIntegertimes = 60;

    RACSignal *timer = [[[RACSignal interval:1 onScheduler:[RACScheduler mainThreadScheduler]] map:^id(id value) {

        return nil;

    }] startWith:nil];

    NSMutableArray *numbers = [[NSMutableArrayalloc] initWithCapacity:times];

    for (inti = times; i >= 0; i--) {

        [numbersaddObject:@(i)];

    }

    return [[[numbers.rac_sequence.signalzipWith:timer] map:^id(RACTuple*tuple) {

        NSNumber *number = tuple.first;

        NSIntegercount = number.integerValue;

        if (count ==0) {

            returnRACTuplePack(@"获取验证码",@YES);

        } else {

            NSString *title = [NSStringstringWithFormat:@"重新获取(%@)", number];

            return RACTuplePack(title,@NO);

        }

    }] takeUntil:self.rac_willDeallocSignal];

}

- (void)setupCodeButton {

    @weakify(self);

    [[[[[[self.codeButton rac_signalForControlEvents:UIControlEventTouchUpInside] map:^id(id value) {

        @strongify(self);

        if([self.bankIDTextField.textisEmptyString]) {

            [SVProgressHUD showErrorWithStatus:@"银行卡号不能为空!"];

            return nil;

        } else {

//            if (![self.bankIDTextField.text isValidBankCardNumber]) {

//                [SVProgressHUD showErrorWithStatus:@"请输入正确的银行卡号!"];

//                return nil;

//            }

        }

        if([self.mobileTextField.textisEmptyString]) {

            [SVProgressHUD showErrorWithStatus:@"手机号码不能为空!"];

            return nil;

        } else {

            if (![self.mobileTextField.textisValidMobileNumber]) {

                [SVProgressHUD showErrorWithStatus:@"请输入有效的手机号码!"];

                return nil;

            }

        }

        [selfrequestCode];

        return [self resendVerificationCode];

    }] startWith:nil] switchToLatest] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(RACTuple *tuple) {

        @strongify(self);

        dispatch_async(dispatch_get_main_queue(), ^{

            [self.codeButton setTitle:tuple.first forState:UIControlStateNormal];

            [self.codeButtonsetEnabled:[tuple.secondboolValue]];

        });

    }];

}

```

不喜勿喷,个人记录方便翻阅,后续如有用到更多场景功能会添加

相关文章

  • RAC初学记录

    个人记录,方便查阅 场景 1. 用户登录,登录按钮需账号密码同时满足某个条件才能点击 NSArray *sign...

  • 2017-12-27

    初学RAC(一) 一:简单...

  • RAC 初学

    1.给按钮绑定方法 2.添加代理方法 3.接收通知 4.KVO MAP 映射的意思,就是创建一个订阅者的映射并且返...

  • ReactiveCocoa & MVVM学习笔记

    网上关于RAC和MVVM的资料非常多,我写这篇主要是因为初学RAC,为自己记个学习笔记。 1. RAC是什么? (...

  • 解耦-用RAC处理网络请求

    最近接手的项目中使用了RAC,也研究学习了下,发现使用RAC确实清晰便利了许多,下面记录一下用RAC处理网络请求实...

  • 晚饭的茶真强劲

    记录一下今天踩过的坑rac使用的时候我们经常使用rac_signalForSelector 来抓代理方法. 有时候...

  • RAC学习记录

    入门http://www.jianshu.com/p/15f9da230f82[https://www.jians...

  • 学习RAC记录

    FRP的核心是信号,信号在ReactiveCocoa(以下简称RAC)中是通过RACSignal来表示的,信号是数...

  • RAC学习记录(1)

    RAC学习记录 先了RAC中的几个术语解释,链式、函数式、响应式 链式,用block作为函数的返回参数,并且blo...

  • RAC(iOS)常用方法

    前言 在学完RAC后发现方法的用法总是会忘,于是简单记录一下在工程中的用法。 RAC常用方法 UIButton点击...

网友评论

      本文标题:RAC初学记录

      本文链接:https://www.haomeiwen.com/subject/xfnrdttx.html