Skip to content

No hassle Objective-C blocks-based KVO library with automatic removal

License

Notifications You must be signed in to change notification settings

jam/CLBlockObservation

 
 

Repository files navigation

CLBlockObservation

Version Platform

No hassle Objective-C blocks-based KVO library with automatic removal

There are so many KVO libraries out there. Couldn't find one that supports both blocks and automatic removal of observers. And that's usually what I need. Just want to bind stuff around.

Installation

CLBlockObservation is available through CocoaPods, to install it simply add the following line to your Podfile:

pod "CLBlockObservation"

Usage

Usage is straightforward. I would recommend including <NSObject+CLBlockObservation.h> in your .pch file.

[observee addObserver:observer keyPath:@"p1" block:^(id oldValue, id newValue) {
  NSLog(@"do something great!");
}];

There's also support for observing multiple keypaths:

[observee addObserver:observer keyPaths:@[ @"p1", @"p2" ] block:^{
  NSLog(@"be awesome!");  
}];

Tests

There's an XCTest project in this repository. It contains a few tests that verify the lifetime management of the observation and a good sample reference.

There's a script that runs the tests from command line:

$ clone https://github.com/eladb/CLBlockObservation
$ cd CLBlockObservation/Tests
$ ./run-tests.sh

Author

Elad Ben-Israel, elad.benisrael@gmail.com

License

CLBlockObservation is available under the MIT license. See the LICENSE file for more info.

About

No hassle Objective-C blocks-based KVO library with automatic removal

Resources

License

Stars

Watchers

Forks

Packages

No packages published