KVO-MVVM
Usage
- First
#import <KVO-MVVM/KVOUIView.h>
or any other available header - Subclass your custom view from
KVOUIView
- Use
mvvm_observe:with:
ormvvm_observeCollection:with:
like this:
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self mvvm_observe:@keypath(self.viewModel.title)
with:^(typeof(self) self, NSString *title) {
self.titleLabel.text = self.viewModel.title;
}];
[self mvvm_observeCollection:@keypath(self.viewModel.values)
with:^(typeof(self) self,
NSArray<NSNumber *> *value,
NSKeyValueChange change,
NSIndexSet *indexes) {
// ...
}];
}
return self;
}
- Do not unobserve any KVO-observings any more
Observing keypaths with weak
properties in it is not supported.
To run the example project, clone the repo, and run pod install
from the Example directory first.
Requirements
Installation
KVO-MVVM is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'KVO-MVVM'
Authors
Anton Bukov, [email protected] Andrew Podkovyrin, [email protected]
License
KVO-MVVM is available under the MIT license. See the LICENSE file for more info.