Closed Tiger6688 closed 9 years ago
- (RACSignal *)didBecomeInactiveSignal { if (_didBecomeInactiveSignal == nil) { @weakify(self); _didBecomeInactiveSignal = [[[RACObserve(self, active) filter:^ BOOL (NSNumber *active) { NSLog(@"active:%@",active); return !active.boolValue; }] map:^(id _) { @strongify(self); return self; }] setNameWithFormat:@"%@ -didBecomeInactiveSignal", self]; } return _didBecomeInactiveSignal; }
//in myviewmodel -(id)init{ //--- [self.didBecomeInactiveSignal subscribeNext:^(id x){ NSLog(@"didBecomeInactiveSignal"); }]; //---
//in myviewcontroller that related with myviewmodel - (void)viewDidLoad { NSLog(@"did load"); }
output: 2014-11-04 23:03:18.714 [5256:60b] active:0 2014-11-04 23:03:18.793 [5256:60b] didBecomeInactiveSignal 2014-11-04 23:03:18.911 [5256:60b] active:0 2014-11-04 23:03:18.913 [5256:60b] active:0 2014-11-04 23:03:19.051 [5256:60b] active:0 2014-11-04 23:03:19.052 [5256:60b] active:0 2014-11-04 23:03:19.082 [5256:60b] view did load
As documented, the activity signals fire once if the current value matches the condition.
output: 2014-11-04 23:03:18.714 [5256:60b] active:0 2014-11-04 23:03:18.793 [5256:60b] didBecomeInactiveSignal 2014-11-04 23:03:18.911 [5256:60b] active:0 2014-11-04 23:03:18.913 [5256:60b] active:0 2014-11-04 23:03:19.051 [5256:60b] active:0 2014-11-04 23:03:19.052 [5256:60b] active:0 2014-11-04 23:03:19.082 [5256:60b] view did load