samedi 27 juin 2015

ReactiveCocoa takeUntil 2 possible signals ?

So I am trying to get the timer to stop upon a completed signal from my updated table and it appears not to be working.

I have gotten the signal to stop when the button is pressed the second time that works well.

However I tried to created a second signal to allow the scheduler to stop, and it does not appear to stop in both options 1 and 2 in the update table view.

Am I writing this correctly, is there a concept I am not understanding?

-(RACSignal*) startTimer {
    return [[[[RACSignal interval:1.0
            onScheduler:[RACScheduler mainThreadScheduler]]
             startWith:[NSDate date]]
             takeUntil:[self.start rac_signalForControlEvents:UIControlEventTouchUpInside]]
             takeUntil:self.completeSignal];
}

-(void) viewDidLoad {


    self.tableView.delegate = self;
    self.tableView.dataSource = self;

    RACSignal* pressedStart = [self.start rac_signalForControlEvents:UIControlEventTouchUpInside];

    @weakify(self);
    RACSignal* textChangeSignal = [[pressedStart map:^id(id value) {
        @strongify(self);
        return [self.start.titleLabel.text isEqualToString:@"Start"] ? @"Stop" : @"Start";
    }] startWith:@"Start"];

    [textChangeSignal subscribeNext:^(NSString* text) {
        @strongify(self);
        [self.start setTitle:text forState:UIControlStateNormal];
    }];


    static NSInteger t = 0;
    [[pressedStart flattenMap:^RACStream *(id value) {
        return [self startTimer];
    }] subscribeNext:^(id x) {
            t = t + 1;
            NSLog(@"%ld",t);
        [self updateTable];
    }];





}

-(void) updateTable {

    // option 1 Doesn't work
        [self.start    sendActionsForControlEvents:UIControlEventTouchUpInside];
// Option 2 doesn't work 
self.completeSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        [subscriber sendCompleted];
        return nil;
    }];
    if ([self.excercises count] > 0 || self.excercises !=nil) {

    }else {
        // stop everything
        // using button signal
    }




}

Aucun commentaire:

Enregistrer un commentaire