-
-
Save quellish/bc7ecfd885c97c60d4c2 to your computer and use it in GitHub Desktop.
correct kvo observe value for key path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in the initializer, or viewWillAppear,etc: | |
[self addObserver:self forKeyPath:keyPath options:options context:(__bridge void*)self]; | |
// in dealloc, or viewDidDisappear, etc: | |
[self removeObserver:self forKeyPath:keyPath context:(__bridge void*)self]; | |
- (void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object change: (NSDictionary *) change context: (void *) context { | |
if ((__bridge id)context == self){ | |
if ([[change valueForKey:NSKeyValueChangeNotificationIsPriorKey] isEqual:@YES]){ | |
// willChange, etc. | |
} else { | |
// didChange, etc. | |
} | |
} else { | |
[super observeValueForKeyPath: keyPath ofObject: object change: change context: context]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment