ReactiveCocoa takeUntil:不发送完成?

时间:2014-08-15 16:28:07

标签: ios reactive-cocoa

我做了一些基本的信号链接。按下按钮后,我想等到loginSignal完成某些操作。信号完成,但我的subscribeCompleted:块未被调用。

直接订阅nextcompletion loginSignal按预期方式工作。那么为什么takeUntil: subscribeCompleted:无法工作?

[[[button rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:loginSignal] subscribeCompleted:^{
    NSLog(@"COMPLETE");
    // Do some other stuff
}];

修改:这里是logAll的输出

2014-08-15 10:52:56.417 app[88791:60b] <RACDynamicSignal: 0x10c58a120> name:  next: <UIButton: 0x10c68a870; frame = (240 80; 40 40); opaque = NO; autoresize = TM+BM; autoresizesSubviews = NO; tag = 1103; layer = <CALayer: 0x10c6894a0>>
2014-08-15 10:52:56.417 app[88791:60b] <RACDynamicSignal: 0x10c58a120> name:  next: <UIButton: 0x10c68a870; frame = (240 80; 40 40); opaque = NO; autoresize = TM+BM; autoresizesSubviews = NO; tag = 1103; layer = <CALayer: 0x10c6894a0>>
2014-08-15 10:53:02.086 app[88791:410b] <RACDynamicSignal: 0x112e2c4b0> name:  next: 1
2014-08-15 10:53:02.087 app[88791:410b] <RACDynamicSignal: 0x10c6ea5d0> name:  next: 1
2014-08-15 10:53:02.087 app[88791:410b] <RACDynamicSignal: 0x10c6ea5d0> name:  next: 1
2014-08-15 10:53:02.088 app[88791:410b] <RACDynamicSignal: 0x10c6b8830> name:  next: 1
2014-08-15 10:53:02.089 app[88791:410b] <RACDynamicSignal: 0x10c6b8830> name:  next: 1
2014-08-15 10:53:02.089 app[88791:410b] <RACDynamicSignal: 0x10c52e570> name:  next: 1
2014-08-15 10:53:02.090 app[88791:410b] <RACDynamicSignal: 0x10c52e570> name:  next: 1

编辑2 loginSignal

RACSignal* loginSignal = [[[RACObserve(obj, loginState) distinctUntilChanged] filter:^BOOL(id value) {
    return ([value integerValue] == LOGGEDIN);
}] takeUntil:[self rac_prepareForReuseSignal]];

1 个答案:

答案 0 :(得分:1)

事实证明,takeUntil:不是获得此行为的正确方法。一旦loginSignal被解雇,它会导致sendCompleted:多次触发(因此似乎不会触发?),即使对于未被点击的按钮也是如此。更好的方法是flattenMap:并发送loginSignal

正确版本:

[[[[[button rac_signalForControlEvents:UIControlEventTouchUpInside] flattenMap:^RACStream *(id value) {
    return loginSignal;
}] take:1] subscribeNext:^(id value){
    // DO STUFF!!!
}];