/MCObserverKit

轻量级的KVO快速绑定工具

Primary LanguageObjective-CMIT LicenseMIT

MCObserverKit

CI Status Version License Platform

Example

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

Requirements

Installation

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

pod 'MCObserverKit'

如何使用

@interface MCTestModel : NSObject

@property (nonatomic, assign) int uuid;
@property (nonatomic, assign) int uuid1;

@property (nonatomic, copy, nullable) NSString *text;

@end

MCTestModel *m1 = [MCTestModel new];
//uuid变化时回调block
[MCObserver(m1, uuid) valueChanged:^(id target, id value) {
    XCTAssert(m1.uuid == 15568);
    [testExpectation fulfill];
}];
//text变化且符合条件时回调block
[MCObserver(m1, text) valueChanged:^(id target, id value) {
    XCTAssert(value);
    [testExpectation fulfill];
} condition:^BOOL(id target, id value) {
    return [value length] > 2;
}];
//uuid变化时回调SEL
[MCObserver(m1, uuid) addTarget:m1 action:@selector(targetCallback:)];

//赋值,触发值变化回调
m1.uuid = 15568;

License

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