Every iOS dev makes a KVO wrapper at some point, here's mine.
SKObserver is an NSObject category that provides a cleaner block based syntax for observing key value changes.
To stop all observers from listening to changes on the object
[object sk_removeAllObservers];
In addition, to remove a specfic observer on the object
id observer = [object sk_addObserverForKeyPath:@"keyPath" withBlock:^(NSDictionary <NSKeyValueChangeKey, id> *change)
{
NSLog(@"Change %@", change);
}];
//when done observing
[object sk_removeObserver:observer];
And that's it! No more long and messy 'observeValueForKeyPath' methods.
If you found an issue or would like to improve SKObserver feel free to raise an issue/submit a PR. You can also reach out to me on Twitter @_sachinkFor reference on how KVO works, I encourage you to check out this post before diving into this library.
SKObserver is available under the MIT License. Check out the LICENSE for more information.