Enabling an UIButton using Reactive Cocoa RACSignal

南楼画角 提交于 2019-12-05 02:48:38

问题


I have a UIButton added to a view. My view also has three text box viz. username, password and confirmPassword. Based on the legitimate content of these text box, I need to enable my signUp button.

Here is my code snippet :-

    UIButton *signUp = [[UIButton alloc]initWithFrame:CGRectMake(10, 100, 50, 20)];
    signUp.backgroundColor = [UIColor greenColor];

    signUp.enabled = NO ;
    [self.view addSubview:signUp];

    RACSignal *formValid = [RACSignal
    combineLatest:@[
    username.rac_textSignal,
    password.rac_textSignal,
    confirmPassword.rac_textSignal
    ]
    reduce:^(NSString *username, NSString *password, NSString *passwordVerification)        {
    return @([username length] > 0 && [password length] > 8 && [password      isEqual:passwordVerification]);
    }];

    RAC(signUp.enabled) = formValid; //Error is here

In the last line, I'm getting two errors:-

  1. Implicit conversion of 'BOOL' (aka 'signed char') to 'id' is disallowed with ARC
  2. Expected identifier

I am new to Reactive Cocoa. Please ignore the mistakes.


回答1:


The RAC() macro takes two arguments at a minimum, the object that's the target and a valid keypath on that object.

Like so:

RAC(signUp, enabled) = formValid;

You're passing it signUp.enabled, which is a single item, and happens to be a BOOL, not an object. After the macro is expanded, the BOOL is passed to a method that expects an object argument, so the compiler complains:

[[RACSubscriptingAssignmentTrampoline alloc] initWithTarget:signUp.enabled nilValue:<#garbage#>][@keypath(signUp.enabled, nil)]



回答2:


Use RAC(signUp, enabled) instead of RAC(signUp.enabled). The RAC macro takes at least two arguments, the object and the keypath you are binding.



来源:https://stackoverflow.com/questions/20266886/enabling-an-uibutton-using-reactive-cocoa-racsignal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!