Recurring signals using ReactiveCocoa (i.e. Repetitive Timers)

How to use ReactiveCocoa to implement ‘repeat every…’ task

Dmitry Seredinov
ReactiveCocoa Way

--

Sometimes you might want to have repetitive task which needs to be executed, say, every 60 seconds.

Of course, you can use ‘native’ Objective-C tools like

[NSTimer scheduledTimerWithTimeInterval:60.0 target:nil selector:@selector(taskToRepeat) userInfo:nil repeats:YES];

But what if you want to use ReactiveCocoa Way to achieve that? Hopefully, you can do that like:

RACSignal *repetitiveEventSignal = [[[RACSignal interval:60] take:1] concat:[RACSignal interval:60]];

After signal created, you can subscribe to `next` events:

[repetitiveEventSignal subscribeNext: ^(NSDate* currentDateTime){
/* … your code here…*/
}];

--

--