Skip to content

Instantly share code, notes, and snippets.

@jwilling

jwilling/gist:5929321

Last active Dec 19, 2015
Embed
What would you like to do?
Handling errors when using toProperty:onObject:.
RAC(self.someOrderedSet) = [[[[[[RACAble(self.searchField.text)
filter:^BOOL(NSString *text) {
return (text.length > 0);
}]
map:^id(NSString *text) {
return [Something searchForAutocomplete:text]; // this signal can send errors
}]
switchToLatest]
catchTo:[RACSignal return:[NSArray array]]]
map:^id(NSArray *objects) {
NSMutableOrderedSet *orderedSet = [NSMutableOrderedSet orderedSet];
[orderedSet addObjectsFromArray:objects];
return orderedSet;
}]
retry];
@joshaber

This comment has been minimized.

Copy link

@joshaber joshaber commented Jul 4, 2013

It's much more likely you want to catch errors directly from +searchForAutocomplete: instead of on the switched signal. That way you don't need to worry about that signal ending with an error:

[[[[RACAble(self.searchField.text)      
  filter:^BOOL(NSString *text) {
    return (text.length > 0);
  }]
  map:^id(NSString *text) {
    return [[Something searchForAutocomplete:text] catchTo:[RACSignal return:@[]]];
  }]
  switchToLatest]
  map:^id(NSArray *tickers) {
    NSMutableOrderedSet *orderedSet = [NSMutableOrderedSet orderedSet];
    [orderedSet addObjectsFromArray:tickers];
    return orderedSet;
  }];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.