Skip to content

NyxReloaded/MLAKeyValueObserverCenter

Repository files navigation

Key Value Observer Center

MLAKeyValueObserverCenter allows you to use K.V.O as you will do with NSNotificationCenter.

Its purpose is to make K.V.O notification more flexible :

  • Selectors and blocks as callback
  • Safe remove observer
  • Allow retrieve observers for a given object’s keyPath

How to use it ?

[[MLAKeyValueObserverCenter defaultCenter] addObserver:self 
                                              selector:@selector(nameDidChange:) 
                                               keyPath:@"name" 
                                                object:self.person];
- (void)nameDidChange:(NSDictionary *)change
{
   // implementation go here
}
[[MLAKeyValueObserverCenter defaultCenter] removeObserver:self];

Using block

id observer = [[MLAKeyValueObserverCenter defaultCenter] addObserverForKeyPath:@"name" 
                                                                        object:self.person 
                                                                    usingBlock:^(NSDictionary *changes) {
        NSLog(@"Name has changed !");
    }];

About

Make K.V.O more flexible

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published