Skip to content

youngsoft/YSObserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YSObserver

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, obq0387_cn@sina.com

License

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

About

一个轻量级的基于block回调通知的对象KVO扩展

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors