To run the example project, clone the repo, and run pod install
from the Example directory first.
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;
MCObserverKit is available under the MIT license. See the LICENSE file for more info.