Bibs
Bibs

Reputation: 1015

Unable to filter RACSignal events

My ViewController contains a UISearchBar and implements the UISearchBarDelegate protocol. I've created a signal for searchBartextDidChange: that fires correctly with subscribeNext:

RACSignal *searchTextChangeSignal = [self rac_signalForSelector:@selector(searchBar:textDidChange:) fromProtocol:@protocol(UISearchBarDelegate)];

[searchTextChangeSignal subscribeNext:^(id x){
  // This works.
}];

At this point, I'd like to filter the results of this filter to 1) Only include text that is greater than 3 characters, and 2) throttled by 300 ms. My attempt:

[[searchTextChangeSignal filter:^(RACTuple *tuple) {
  NSString *textEnteredIntoSearchBar = (NSString *)tuple.second;
  return textEnteredIntoSearchBar.length > 3;
}] throttle:300];```

The code above doesn't work. The blocks are never executed. If I replace the filter method with subscribeNext, the subscribeNext block does execute. Furthermore, XCode autocompletes the filter method above, so the method is available. Is there something I'm missing here? What's the correct way to do this? Any help is much appreciated.

Upvotes: 0

Views: 202

Answers (1)

Dave Lee
Dave Lee

Reputation: 6489

The missing understanding is that signals do not perform any work until they are subscribed to. Call one of the subscribe methods following the throttle, and you will see the data start to flow through.

Upvotes: 1

Related Questions