简体   繁体   中英

ReactiveCocoa `rac_textSignal` map completed event

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?

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 ...
}];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM