I have a UITextField
and try to react to textField.text
changes:
self.textField.delegate = self;
[self.textField.rac_textSignal map:^id(NSString *text) {
return @(YES); // breakpoint here
}];
I'm running through the tutorial to learn ROC
. I've noticed, that the block is being called when I type new character, but not when I delete old character. How to fix it..? I want the action to be called when I delete previous character.
Eg: on the left what is inside textField.text
, on right - what's happening:
a
- hits breakpoint ab
- hits breakpoint abc
- hits breakpoint ab
- nothing happensDisclaimer: As I'm just learning this framework and don't want to make first steps on different version, i'm using same version of ROC
as in the tutorial:
pod 'ReactiveCocoa', '2.1.8'
You can check out that this code works well instead of yours.
[self.usernameTextField.rac_textSignal subscribeNext:^(id x) {
NSLog(@"%@", x);
}];
The difference is that my code have an subscribeNext:
method call.
Basic concept here is that you need subscription to execute you code. map:
is the operator that changes input data only when data arrived. subscribeNext:
/ subscribeCompleted:
/ subscribeError:
are the root cause of the forcing signals to send data to the chain in the ReactiveCocoa.
Probably you should read the official framework overview from the ReactiveCocoa team.
UPDATE:
For the current situation applying subscribeNext
to the end will fix issue:
[[self.usernameTextField.rac_textSignal
map:^id(id x) {
NSLog(@"%@", x);
return x;
}]
subscribeNext:^(id x) {
NSLog(@"%@", x);
}];