Last active
April 19, 2017 10:36
-
-
Save lukeredpath/9051769 to your computer and use it in GitHub Desktop.
ReactiveCocoa signal for keyboard done button taps
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
#import "UITextField+RACKeyboardSupport.h" | |
#import <ReactiveCocoa/RACEXTScope.h> | |
#import <ReactiveCocoa/NSObject+RACDescription.h> | |
@implementation UITextField (RACKeyboardSupport) | |
- (RACSignal *)rac_keyboardReturnSignal { | |
@weakify(self); | |
return [[[[RACSignal | |
defer:^{ | |
@strongify(self); | |
return [RACSignal return:self]; | |
}] | |
concat:[self rac_signalForControlEvents:UIControlEventEditingDidEndOnExit]] | |
takeUntil:self.rac_willDeallocSignal] | |
setNameWithFormat:@"%@ -rac_keyboardReturnSignal", [self rac_description]]; | |
} | |
@end |
@aehike code is released under the do whatever you want with it license (™).
Maybe this license: http://en.wikipedia.org/wiki/WTFPL
I had to add a skip:1 before concat: to skip the initial next call. Otherwise my UI logic would be executed as soon as I setup my bindings which isn't the contract of the function imho. It should only trigger next if the user really hits the return button.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! Could you please apply a license to this code so that it can be used? (e.g. MIT)