2014-11-14 87 views
3

反應詞是新來處理鏈接請求,所以,請大家幫忙尋找這個場景的最佳解決方案: 我的Youtube API工作。我想加載VideoCategories,然後爲每個類別獲取一個頂級視頻,然後爲每個視頻加載縮略圖,將其累積到模型中,然後才發送信號到表視圖以重新加載數據。 我請求類是這樣的:最佳實踐使用反應可可

[[[TRYoutubeManager manager] rac_GET:@"videoCategories" parameters:parameters] map:^id(id responseObject) { 
    TRYoutubeListResponseModel *listModel = 
    [MTLJSONAdapter modelOfClass:[TRYoutubeListResponseModel class] fromJSONDictionary:responseObject error:nil]; 
    listModel.items = [[listModel.items.rac_sequence filter:^BOOL(TRYoutubeVideoCategoryModel *categoryModel) { 
     return categoryModel.assignable; 

    }] array]; 
    return listModel; 
    }]; 

那麼,如何爲每個listModel.items發送請求,然後結合的結果,然後將信號表視圖?

回答

0

好的,對於仍然懷疑的每個人。更抽象地解釋:

// You get your list ob objects here 
[[[Manager getList] flattenMap:^RACStream *(NSArray *yourList) { 
    NSMutableArray *listItemsSignals = [NSMutableArray array]; 
    for (ItemClass *item in yourList) { 
    //Something that produces signals 
    RACSignal *itemSignal = [item imageSignal]; 
    [listItemsSignals addObject: itemSignal] 
    } 

    return [RACSignal combineLatest:listItemsSignals]; 
}] subscribeNext:^(RACTuple *values) { 
    // All your values are here 
}];