内容编辑输入请求作为 RACSignal

Content editing input request as RACSignal

我正在努力使我的代码更实用、更具反应性。我创建这样的请求:

[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
    PHContentEditingInputRequestOptions *options = [PHContentEditingInputRequestOptions new];
    options.networkAccessAllowed = YES;
    options.progressHandler = ^(double progress, BOOL *stop) {
        // update UI
    };

    [asset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
        // subscriber send next/completed/error
    }];

    return [RACDisposable disposableWithBlock:^{
        // here I should kill request if still active
    }];
}];

要取消 iCloud 请求,我必须在 progressHandler 中设置 *stop = YES;。如何以反应方式做到这一点?

我已经设法通过 NSMutableArray 在块中捕获来解决这个问题。

[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
    // -- Change ---------------------------------------------------
    NSMutableArray *flag = [NSMutableArray array];
    // -- Change End -----------------------------------------------

    PHContentEditingInputRequestOptions *options = [PHContentEditingInputRequestOptions new];
    options.networkAccessAllowed = YES;
    options.progressHandler = ^(double progress, BOOL *stop) {

        // -- Change ---------------------------------------------------
        if(flag.count > 0) {
            *stop = YES;
        } else {
            // update UI
        }
        // -- Change End -----------------------------------------------
     };

    [asset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
        // subscriber send next/completed/error
    }];

    return [RACDisposable disposableWithBlock:^{
        // -- Change ---------------------------------------------------
        [flag addObject:@0];
        // -- Change End -----------------------------------------------
    }];
}];