سؤال

I 'm new to Reactive Cocoa. I'm trying to set up a button enable property through a signal. I've the following code snippet which works fine:

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] > 3 && [password isEqual:passwordVerification]);
                        }];

RAC(signUp,enabled) = formValid;

However, I also came across another piece of code that also works fine:

    [[RACSignal 
      combineLatest:@[username.rac_textSignal, password.rac_textSignal,confirmPassword.rac_textSignal]
      reduce:^(NSString *firstName, NSString *passwd, NSString *confirmPass){
             return @( firstName.length > 0 && passwd.length > 0 && confirmPass.length > 0);
      }] setKeyPath:@"enabled" onObject:resetButton];

I wanted to get clarified whether both the ways are totally similar in their internal implementation or whether one is better than other in some scenarios. In simple terms can anybody explain me the differences with respect to performance???

Thank You

هل كانت مفيدة؟

المحلول

If you check out the the RAC macro and follow the trail, you'll find that it ultimately results in a call to -setKeyPath:onObject:. The RAC macro is for convenience (syntactic sugar), with no performance impact. The only case I've seen where it is necessary to use -setKeyPath:onObject: is when you need access to the disposable that gets created by the underlying subscription. I don't think you'll find many cases where you must dispose the underlying subscription yourself.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top