Skip to content

Latest commit

 

History

History
executable file
·
45 lines (31 loc) · 1.16 KB

README.md

File metadata and controls

executable file
·
45 lines (31 loc) · 1.16 KB

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 !");
    }];