如何从ReactiveCocoa信号中获取"旧值"?

zak*_*ces 9 objective-c key-value-observing reactive-programming ios reactive-cocoa

如果我像这样使用RACable:

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

}];
Run Code Online (Sandbox Code Playgroud)

如何才能访问myProp的旧值(在更改之前导致信号触发)?所以我可以像这样访问它:

[RACAbleWithStart(self.myProp) subscribeNext:^(id x) {
   // Do stuff
   id newValue = x;
   id oldValue = RAC_oldValue;
}];
Run Code Online (Sandbox Code Playgroud)

Tom*_*Bąk 4

我已经成功地使用了这个片段:

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

来源:ReactiveCocoa 文档