- Runtime 是基于 C 实现的是一套比较底层的纯C语言API, 属于1个C语言库, 包含了很多底层的C语言API。在我们平时编写的OC代码中, 程序运行过程时, 其实最终都是转成了runtime的C语言代码, runtime算是OC的幕后工作者
- 要使用 Runtime 的函数,必须导入 objc/runtime.h
-
- OC中的方法调用[接受者 方法名]这个过程依赖于 Runtime 机制
- idobjc_msgSend(id theReceive, SEL theSelector, …)[发送消息的底层调用]
- theReceive:接收消息的对象 theSelector:消息名称
- idobjc_msgSend(id theReceive, SEL theSelector, …)[发送消息的底层调用]
- OC中的方法调用[接受者 方法名]这个过程依赖于 Runtime 机制
- 获取类中的方法
- Method*methodPtr = class_copyMethodList(myClass, &outCount);
- 获取方法的名称
- Method method = methodPtr[i];
- SEL selector =method_getName(method);
- NSString *name =NSStringFormSelector(selector);
- 查看类中的实例变量
- Ivar *ivarPtr =class_copyIvarList(myClass, &outCount);
- 获取实例变量的名称
- Ivar ivar = ivarPtr[i];
- const char*chName = ivar_getName(ivar);
- NSString *name = [NSString stringWithUTF8String: chName];
- 查看类中的属性
- objc_property_t *propertyPtr =class_copyPropertyList(myClass, &outCount);
- 获取属性的名称
- objc_property_t property = propertyPtr[i];
- const char *ch =property_getName(property);
- NSString *name = [NSString stringWithUTF8String: chName];
C_Runtime机制_s
最新推荐文章于 2023-09-13 13:57:17 发布