https://github.com/misterbooo/kvo-
KVO实现原理
https://github.com/misterbooo/kvo-
Last synced: 8 months ago
JSON representation
KVO实现原理
- Host: GitHub
- URL: https://github.com/misterbooo/kvo-
- Owner: MisterBooo
- Created: 2017-12-18T07:02:57.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-19T03:38:24.000Z (almost 8 years ago)
- Last Synced: 2025-01-11T13:47:56.579Z (9 months ago)
- Language: Objective-C
- Size: 35.2 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# KVO-
KVO实现原理```
- (void)yy_addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(nullable void *)context{
NSString *oldName = NSStringFromClass([self class]);
NSString *newName = [@"YYKVO" stringByAppendingString:oldName];
Class MyClass = objc_allocateClassPair([self class], newName.UTF8String, 0);
class_addMethod(MyClass, @selector(setName:), (IMP)test, "v@:@");
objc_registerClassPair(MyClass);
object_setClass(self, MyClass);
}void test(){
NSLog(@"test");
}
```