RACSignal:RACSignal 代码未执行
RACSignal: RACSignal code is not executed
有没有好心人可以帮我解决这个问题?
这是我的场景:
我需要将表单附件上传到服务器。所以这里是步骤:
使用 Web 服务从服务器检索附件 header。
将附件 header 与本地附件匹配。
上传附件到服务器。
问题:
使用 RACSignal 我可以成功获取附件 headers 但是当使用 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];
}
因为 uploadFormItemAttachments
returns RACSignal
你应该使用 flattenMap
而不是 map
有没有好心人可以帮我解决这个问题?
这是我的场景:
我需要将表单附件上传到服务器。所以这里是步骤:
使用 Web 服务从服务器检索附件 header。
将附件 header 与本地附件匹配。
上传附件到服务器。
问题:
使用 RACSignal 我可以成功获取附件 headers 但是当使用 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];
}
因为 uploadFormItemAttachments
returns RACSignal
你应该使用 flattenMap
而不是 map