facebookarchive / KVOController

Simple, modern, thread-safe key-value observing for iOS and OS X.
Other
7.34k stars 925 forks source link

is KVOController support listen to self keyPath ? #133

Closed ifelseboyxx closed 7 years ago

ifelseboyxx commented 7 years ago
[self.KVOControllerNonRetaining observe:self keyPath:@"age" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld block:^(id  _Nullable observer, id  _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {

        NSString *new = change[NSKeyValueChangeNewKey];

        NSString *old = change[NSKeyValueChangeOldKey];

        NSLog(@"new: %@ - old: %@",new,old);

    }];

when pop this viewcontroller crash:

2017-08-22 14:16:32.248 KVODemo[95089:23217331] new: 26 - old: <null>
2017-08-22 14:16:32.990 KVODemo[95089:23217331] new: 26 - old: 26
2017-08-22 14:16:33.282 KVODemo[95089:23217331] new: 26 - old: 26
2017-08-22 14:16:35.014 KVODemo[95089:23217331] FBViewController释放了
2017-08-22 14:16:35.015 KVODemo[95089:23217331] Person释放了
2017-08-22 14:16:35.018 KVODemo[95089:23217331] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x7fd0d200f860 of class FBViewController was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x61800003b0a0> (
<NSKeyValueObservance 0x618000044d40: Observer: 0x618000085320, Key path: age, Options: <New: YES, Old: YES, Prior: NO> Context: 0x61800007e340, Property: 0x618000044e30>
)'