Search code examples
iosswiftreactive-cocoa

Delay RACObserve subcribeNext call to one per second


I'm observing a class' attribute that changes every .2 second. I would like to delay the observing to each second.

I tried:

RACObserve(object, keyPath: "attribute").delay(1).subscribeNext { 
    // DO STUFF
}

But the subscribeNext is still called every .2 second.

Any suggestion?


Solution

  • I found a way to achieve this:

    RACObserve(object, keyPath: "attribute").combineLatestWith(RACSignal.interval(1, onScheduler: RACScheduler.mainThreadScheduler()))
      .subscribeNext { 
      // DO STUFF
    }
    

    You can add a map to get only the attribute value instead of a RACTuple