문제

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");
}];
도움이 되었습니까?

해결책

-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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top