https://github.com/youngsoft/ysobserver
一个轻量级的基于block回调通知的对象KVO扩展
https://github.com/youngsoft/ysobserver
Last synced: about 1 year ago
JSON representation
一个轻量级的基于block回调通知的对象KVO扩展
- Host: GitHub
- URL: https://github.com/youngsoft/ysobserver
- Owner: youngsoft
- License: mit
- Created: 2019-04-12T07:02:52.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-29T03:55:12.000Z (about 7 years ago)
- Last Synced: 2025-03-22T04:32:56.093Z (over 1 year ago)
- Language: Objective-C
- Size: 35.2 KB
- Stars: 37
- Watchers: 3
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# YSObserver
[](https://travis-ci.org/youngsoft/YSObserver)
[](https://cocoapods.org/pods/YSObserver)
[](https://cocoapods.org/pods/YSObserver)
[](https://cocoapods.org/pods/YSObserver)
一个轻量级的通过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 *)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](https://cocoapods.org). To install
it, simply add the following line to your Podfile:
```ruby
pod 'YSObserver'
```
## Author
youngsoft, obq0387_cn@sina.com
## License
YSObserver is available under the MIT license. See the LICENSE file for more info.