2

I'm new to Reactive Cocoa.

I need to trigger stuff when white space gets added to a UITextView, after replacing the text view text with a trimmed version. So basically I am looking for some sort of completion event. I imagine this is a straightforward thing, but I must be missing something essential... This is what I have:

RACSignal *whitespaceSignal = [self.field.rac_textSignal filter:^BOOL(NSString *input) {
    return [self textContainsWhitespace:input];
}];

RAC(self.field, text) = [whitespaceSignal map:^id(NSString *input) {
    // The stuff that needs to happen *after* the text field has 
    // got the new, trimmed value.. But here it gets triggered before 
    // the UITextView updates its value.
    // [self respondToWhiteSpaceTrimmedEvent];
    return [self trimWhitespace:input];
}];

I've tried several combinations of subscribeCompleted, then, completed blocks, but none of them get called.

How do I detect when self.field.text has updated its value in response to the whitespaceSignal, and only then trigger my side effects?

Elise
  • 5,086
  • 4
  • 36
  • 51
  • Did you try `doNext` after `map`? You should receive updated "trimmed" value in doNext and you can respond to the trimmed event value inside doNext block – Nimble Feb 09 '16 at 18:14
  • @Nimble thanks, unfortunately this is not getting called either. – Elise Feb 09 '16 at 18:24
  • Correction, `doNext` does in fact get called, but it is useless for me if the `UITextView`'s text hasn't updated yet by that point (and it isn't). `doComplete` does not get called. – Elise Feb 09 '16 at 19:29
  • please explain what exactly do you want to achieve, maybe it can be done using a different feature of Reactive Cocoa – Michał Ciuba Feb 09 '16 at 20:55

1 Answers1

0

Did you ever subscribe the signal you create? you filter/map the signal but it seems obvious that you didn't subscribe on the signal so I assume that is why.

[[self.field.rac_textSignal map:^id(NSString *input) {
    // The stuff that needs to happen *after* the text field has 
    // got the new, trimmed value.. But here it gets triggered before 
    // the UITextView updates its value.
    // [self respondToWhiteSpaceTrimmedEvent];
    return [self trimWhitespace:input];
}] subscribeNext:^(id x) {
    // Do some stuff after you replace whitespace ...
}];
REALFREE
  • 4,378
  • 7
  • 40
  • 73