KVO-MVVM
使用
- 首先导入任意可用头文件,如
#import <KVO-MVVM/KVOUIView.h>
- 从
KVOUIView
派生您的自定义视图 - 使用
mvvm_observe:with:
或mvvm_observeCollection:with:
,例如
- (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;
}
- 不再需要取消KVO观测
不支持的OX-观测中的键路径包含弱引用属性。
要运行示例项目,先克隆仓库,然后从示例目录运行pod install
。
要求
安装
KVO-MVVM可以通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中
pod 'KVO-MVVM'
作者
安东·布科夫,[email protected] 安德鲁·波多柯尔金,[email protected]
许可证
KVO-MVVM 在MIT许可证下可用。更多信息请参见LICENSE文件。