Latest 0.2.0
Homepage https://github.com/youngsoft/YSObserver
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

一个轻量级的通过Block执行通知回调的对象KVO扩展,整个库一共200行代码。

Example

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

How to use

  • Normally KVO:

@interface Observer:NSObject

@end

@implementation Observer

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"frame"]){
        NSLog(@"the frame=%@", change[NSKeyValueChangeNewKey]);
    }
}

@end

UIView *view = [UIView new];
Observer *observer = [Observer new];

[view addObserver:observer forKeyPath:@"frame"  options:NSKeyValueObservingOptionNew  context:NULL];
view.frame = CGRectZero;
  • YSObserver

UIView *view = [UIView new];
[view ys_addObserver:anyObject forKeyPath:@"frame" withBlock:^(id newVal, id OldVal){

    NSLog(@"the frame=%@", newVal);
}];

Requirements

Installation

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

pod 'YSObserver'

Author

youngsoft, [email protected]

License

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

Latest podspec

{
    "name": "YSObserver",
    "version": "0.2.0",
    "summary": "A short description of YSObserver.",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/youngsoft/YSObserver",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "youngsoft": "[email protected]"
    },
    "source": {
        "git": "https://github.com/youngsoft/YSObserver.git",
        "tag": "0.2.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "YSObserver/Classes/**/*"
}

Pin It on Pinterest

Share This