Skip to content

Instantly share code, notes, and snippets.

@hsavit1
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsavit1/bd9c58b2e53c89d25b8a to your computer and use it in GitHub Desktop.
Save hsavit1/bd9c58b2e53c89d25b8a to your computer and use it in GitHub Desktop.
RAC vs The Standard Implementations
///////
//signal
///////
//conventional
- (BOOL)isFormValid {
return [self.usernameField.text length] > 0 &&
[self.emailField.text length] > 0 &&
[self.passwordField.text length] > 0 &&
[self.passwordField.text isEqual:self.passwordVerificationField.text];
}
#pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string
{
self.createButton.enabled = [self isFormValid];
return YES;
}
//RAC
RACSignal *formValid = [RACSignal
combineLatest:@[
self.username.rac_textSignal,
self.emailField.rac_textSignal,
self.passwordField.rac_textSignal,
self.passwordVerificationField.rac_textSignal
]
reduce:^(NSString *username, NSString *email, NSString *password, NSString *passwordVerification) {
return @([username length] > 0 && [email length] > 0 && [password length] > 8 && [password isEqual:passwordVerification]);
}];
RAC(self.createButton.enabled) = formValid;
/////Sequence//////
RACSequence *normalizedLongWords = [[words.rac_sequence
filter:^ BOOL (NSString *word) {
return [word length] >= 10;
}]
map:^(NSString *word) {
return [word lowercaseString];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment