如何映射来自sendError的错误:在RACSignal上

时间:2014-02-07 10:51:40

标签: reactive-cocoa racsignal

这非常麻烦

RACSignal *originalSignal = ...;

RACSignal *mappedSignal = [[[[[originalSignal publish] autoconnect] materialize] map:^id(RACEvent *event) {
    if(event.eventType == RACEventTypeError)
    {
        return [RACEvent eventWithError:[self errorForHelperError:event.error]];
    }
    return event;
}] dematerialize];

1 个答案:

答案 0 :(得分:7)

-catch:可让您更优雅地处理这个问题:

RACSignal *mappedSignal = [originalSignal catch:^(NSError *error) {
    return [RACSignal error:[self errorForHelperError:error]];
}];