Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the "old value" from a ReactiveCocoa signal?

If I'm using RACable like this:

[RACAbleWithStart(self.myProp) subscribeNext:^(id x) {
   // Do stuff

}];

How can can I access the old value of myProp (before the change the caused the signal to fire)? So I can access it like this:

[RACAbleWithStart(self.myProp) subscribeNext:^(id x) {
   // Do stuff
   id newValue = x;
   id oldValue = RAC_oldValue;
}];
like image 733
zakdances Avatar asked Apr 17 '13 21:04

zakdances


1 Answers

I have used this snippet with success:

[[object rac_valuesAndChangesForKeyPath:@"property" options:NSKeyValueObservingOptionOld observer:self] subscribeNext:^(RACTuple *tuple) {
    id newObject = tuple.first;
    NSDictionary *change = tuple.second;
    id oldObject = change[NSKeyValueChangeOldKey];
}];

Source: ReactiveCocoa documentation

like image 121
Tomasz Bąk Avatar answered Oct 25 '22 08:10

Tomasz Bąk