Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 1.97 KB

README.md

File metadata and controls

55 lines (42 loc) · 1.97 KB

JFObservableArray

Version License Platform

Usage

To run the tests, clone the repo, and run pod install from the Example directory first.

Installation

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

pod "JFObservableArray"

Usage

JFObservableArray is a KVO-compliant array wrapper that informs observers of changes to the array's underlying structure. Over time the class will support more and more of the NSMutableArray interface. Clients can set up KVO as follows:

JFObservableArray *array = [[JFObservableArray alloc] initWithArray:@[]];
[array addObserver:self forKeyPath:@"self" options:NSKeyValueObservingOptionNew context:nil];

And the changes can be observed as follows:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    switch ([change[NSKeyValueChangeKindKey] integerValue]) {
        case NSKeyValueChangeInsertion: {
            // data was inserted at the indexes in change[NSKeyValueChangeIndexesKey]
            break;
        }
        case NSKeyValueChangeRemoval: {
            // data was removed at the indexes in change[NSKeyValueChangeIndexesKey]
            break;
        }
        case NSKeyValueChangeReplacement: {
            // data was replaced at the indexes in change[NSKeyValueChangeIndexesKey]
            break;
        }
        default:
            break;
        }
}

Author

Jamie Forrest

License

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