I'm completely new to the Reactive Cocoa Framework and i'm just doing some simple tests but i'm encountering a problem that i would like to understand.
Basically i'm just doing an API call to fetch a JSON object from my server, i want to do this with RAC. So my steps are the following:
First i build the RACCommand this way:
RACCommand *getLatestVersionCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
return [[[API sharedInstance] getLatestAppVersion]
materialize];
}];
Now i create the signal and subscribe to it this way:
RACSignal *versionCodeSignal = [[getLatestVersionCommand.executionSignals flatten] deliverOn:[RACScheduler mainThreadScheduler]];
[[versionCodeSignal
map:^id(NSDictionary *responseObject) {
return responseObject;
}]
subscribeNext:^(NSDictionary *responseObject) {
NSArray *allVersions = [[NSArray alloc] initWithArray:[responseObject objectForKey:KEY_VERSIONS]];
for(NSDictionary *version in allVersions) {
NSString *device = [version objectForKey:KEY_DEVICE];
if([device isEqualToString:KEY_IOS]) {
NSString *latestVersionName = [[version objectForKey:KEY_VERSION] objectForKey:KEY_NAME];
if([APP_VERSION compare:latestVersionName options:NSNumericSearch] == NSOrderedAscending) {
//There is a new version!
NSLog(@"There is a new version!!!");
}
}
}
}];
Finally I execute the command this way
[getLatestVersionCommand execute:self];
The problem i'm facing is that in the subscribeNext block, the object i receive is an RACEvent object and not the dictionary i'm expecting. I know i'm doing something wrong and not understanding the full flow correctly, i tried adding the map function that i thought i didn't need just to test and nothing.
The only way i found is to convert the response in the map block to a RACEvent and return its value but that doesn't seem to me the right way to go.
Any light will be greatly appreciated.
Remove the call to -[RACSignal materialize]
from your command's signal block.