QOP
(Queen of pain)是一款轻量级的数据绑定方案,底层采用KVO
实现,链式调用优雅简单,并且使用者不需要关心循环引用及内存释放问题。
- 引用头文件
#import <QOP.h>
- 为避免多次监听同一属性可先进行
QOPUNObserve
,再进行QOPObserve
__weak typeof(self) ws = self;
QOPUNObserve(object, identifier);
[QOPObserve(object, identifier) update:^(id observer, id updatedValue) {
ws.title = updatedValue;
}];
- 自定义数据绑定的监听者和监听策略
// QOPKVOPolicy is KVO policy
[QOPSPObserve(observer, target, keypath, QOPKVOPolicyInitial | QOPKVOPolicyAlways) update:^(id observer, id updatedValue) {
NSLog(@"first exe and always exe");
}];
Podfile
中添加即可:
pod 'QOP'