Question

I am testing reactive cocoa. In the underneath code I would expect the output to be :

name : Item 1
arr : a1
arr : a2
name : Item 2
arr : b1
arr : b2 
done

but I get different unpredictable results for example :

name : Item 1
arr : a1
arr : b1
name : Item 2
arr : a2
arr : b2 
done

Why is this happening? How can I force Reactive Cocoa to give me the first output?

NSArray * arr = @[@{@"name":@"Item 1", @"array" : @[@"a1",@"a2"]} , @{@"name":@"Item 2", @"array":@[@"b1",@"b2"]}];

[[[arr rac_sequence].signal flattenMap:^RACStream *(NSDictionary *dict) {
        NSArray * arr = dict[@"array"];
        NSLog(@"name : %@", dict[@"name"]);

       return  [[arr rac_sequence].signal flattenMap:^RACStream *(NSString *value1) {
            NSLog(@"arr %@",value1);
            return nil;
        }];


}]subscribeCompleted:^{
    NSLog(@"done");
}];
Was it helpful?

Solution

-signal converts the sequence to a signal which sends asynchronously. So it's not terribly surprising that you're seeing some indeterminacy.

What you want is to use -signalWithScheduler:RACScheduler.immediateScheduler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top