I'm exploring ReactiveCocoa and trying to see whats possible. The issues i'm having is chaining a few network requests together.
I have 2 calls, the first gets a list of identifiers, then for each identifier I make a call to get data corresponding to that id and create a model object and return an array of the objects.
I'm using RACExtensions for AFNetworking to make the requests. Code looks something like this:
- (RACSignal *) identifersInfo
{
return [[[[self identifiersSignal] flattenMap:^RACStream *(RACTuple *tuple) {
RACTupleUnpack(AFHTTPRequestOperation *operation, id responseObject) = tuple;
NSArray *identifiers = responseObject[@"Identifiers"];
NSArray *requests = [self httpRequestsWithIdentifiers: identifiers];
return [self.client rac_enqueueBatchOfHTTPRequestOperationsWithRequests: requests];
}] collect] map:^id(RACTuple *tuple) {
RACTupleUnpack(AFHTTPRequestOperation *operation, id responseObject) = tuple;
Model *model = [[Model alloc] init];
model.title = responseObject[@"Title"];
model.description = responseObject[@"Description"];
model.lastUpdated = responseObject[@"LastUpdated"];
return model;
}];
}
identifiersSignal method looks like this:
- (RACSignal *) identifiersSignal
{
return [self.client rac_getPath: @"identifiers" parameters: nil];
}
This returns json dictionary which looks like:
{
"Identifiers": [
3,
4,
21
]
}
I'm actually mocking these calls at the moment and I know they work independently, I'm just trying to piece them together using ReacticeCocoa.
I can't figure out or find any decent samples on how this could be achieved using ReactiveCocoa, although I'm pretty confident it could be.