RACSignal:未执行RACSignal代码

时间:2016-11-12 04:06:25

标签: objective-c reactive-cocoa racsignal

有没有一个愿意帮助我解决这个问题的灵魂?

这是我的情景:

我需要将表单附件上传到服务器。以下是步骤:

  1. 使用Web服务从服务器检索附件标题。

  2. 将附件标题与本地附件匹配。

  3. 将附件上传到服务器。

  4. 问题:

    使用RACSignal我可以成功获取附件标题但是当使用NSArray上传附件时,UploadFormItemAttachments方法的内部RACSignal将不会执行。

    其他信息:

    这是显示如何处理RACSignals的代码段。 BatchSignal永远不会被执行!:

    [[[self getFormItemAttachmentHeaders:listName
                              topListItemID:form.topListItemID
                                      form:form
         ] map:^id(NSMutableArray* value) {
            NSArray* attachmentHeaders = [value copy];
    
            // the code of uploadFormItemAttachments is called but the inner signal does not execute. Why?
            return [self uploadFormItemAttachments:pendingAttachments
                                            attachmentHeaders:attachmentHeaders
                                                         form:form];
            }
          ] subscribeNext:^(id value) {
              // I was expecting the completion result form uploadFormItemAttachments here.
            }
         ];
    

    这是迭代附件数组并将其上传到服务器的方法:

    - (RACSignal *)uploadFormItemAttachments:(NSArray*)pendingAttachments attachmentHeaders:(NSArray*)attachmentHeaders form:(SEFSManagedForm*)form
    {
    
      RACSignal* batchSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        [attachmentHeaders enumerateObjectsUsingBlock:^(SEFSFormItemAttachmentHeader* attachmentHeader, NSUInteger idx, BOOL *stop)
         {
           // Look for the local attachment using attachment header from server
    
           NSPredicate* predicate = [NSPredicate predicateWithFormat:@"identifier = %@", attachmentHeader.document];
           NSArray* foundAttachment = [pendingAttachments filteredArrayUsingPredicate:predicate];
    
           SEFSManagedAttachment* fullAttachment = foundAttachment[0];
    
           RACSignal* uploadFormItemAttachmentSignal = [[self uploadFormItemAttachment:fullAttachment
                                                                      attachmentHeader:attachmentHeader                                                            ] map:^id(NSNumber* value) {
             NSMutableArray* valuesArray = [NSMutableArray array];
             [valuesArray addObject:value];
             [valuesArray addObject:attachmentHeader.document];
             RACTuple* tuple = [RACTuple tupleWithObjectsFromArray:valuesArray
                                                convertNullsToNils:YES];
             return tuple;
           }];
    
    
           [subscriber sendNext:uploadFormItemAttachmentSignal];
         }];
    
        [subscriber sendCompleted];
        return nil;
      }];
    
      return [batchSignal flatten:2];
    }
    

1 个答案:

答案 0 :(得分:0)

由于uploadFormItemAttachments返回RACSignal,您应该使用flattenMap代替map