user1309226 user1309226 - 1 year ago 144
Objective-C Question

RACSignal: RACSignal code is not executed

Is there a willing soul who could kindly help me with this problem?

This is my scenario:

I need to upload form attachments to the server. So here are the steps:

  1. Retrieve attachment headers from server using Web service.

  2. Match the attachment header with local attachments.

  3. Upload attachments to server.

The Problem:

Using RACSignal I can successfully obtain the attachment headers but when it's time to upload the attachments using NSArray the inner RACSignal of the UploadFormItemAttachments method will not execute.

Additional Information:

This is the code snippet that shows how the RACSignals are handled. BatchSignal is never executed!:

[[[self getFormItemAttachmentHeaders:listName
] 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
] subscribeNext:^(id value) {
// I was expecting the completion result form uploadFormItemAttachments here.

This the method that iterates over the attachments array and uploads it to the server:

- (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
return tuple;

[subscriber sendNext:uploadFormItemAttachmentSignal];

[subscriber sendCompleted];
return nil;

return [batchSignal flatten:2];

Answer Source

Since uploadFormItemAttachments returns RACSignal you should use flattenMap instead map

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download