Last active
August 29, 2015 14:23
-
-
Save hsavit1/bd9c58b2e53c89d25b8a to your computer and use it in GitHub Desktop.
RAC vs The Standard Implementations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////// | |
//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