C_Runtime机制_s

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值