Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Last active April 19, 2017 10:36
Show Gist options
  • Save lukeredpath/9051769 to your computer and use it in GitHub Desktop.
Save lukeredpath/9051769 to your computer and use it in GitHub Desktop.
ReactiveCocoa signal for keyboard done button taps
#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
@aehlke
Copy link

aehlke commented Mar 23, 2014

Thanks! Could you please apply a license to this code so that it can be used? (e.g. MIT)

@lukeredpath
Copy link
Author

@aehike code is released under the do whatever you want with it license (™).

@nickcheng
Copy link

@MBulli
Copy link

MBulli commented Dec 1, 2014

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