Skip to content

Instantly share code, notes, and snippets.

@sTinGe
Last active August 18, 2018 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sTinGe/7697211126f295290901435078405e41 to your computer and use it in GitHub Desktop.
Save sTinGe/7697211126f295290901435078405e41 to your computer and use it in GitHub Desktop.
@interface NSObject(NSKeyValueObserverRegistration)
/* Register or deregister as an observer of the value at a key path relative to the receiver.
The options determine what is included in observer notifications and when they're sent, as described above,
and the context is passed in observer notifications as described above. You should use
-removeObserver:forKeyPath:context: instead of -removeObserver:forKeyPath: whenever possible because it allows
you to more precisely specify your intent. When the same observer is registered for the same key path multiple times,
but with different context pointers each time, -removeObserver:forKeyPath: has to guess at the context pointer when
deciding what exactly to remove, and it can guess wrong.
*/
- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(nullable void *)context;
- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath context:(nullable void *)context API_AVAILABLE(macos(10.7), ios(5.0), watchos(2.0), tvos(9.0));
- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath;
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment