美文网首页
附录:runtime函数

附录:runtime函数

作者: juriau | 来源:发表于2020-06-22 20:09 被阅读0次

获得对象的类名

const char* object_getClassName(id obj)

获得方法数组(methodList)

Method* class_copyMethodList(Class cls, unsigned int * outCount) 
- (void)getMethods:(Class) cls{
    unsigned int count;
    Method* methodList = class_copyMethodList(cls, &count);
    
    NSMutableArray* arr = [NSMutableArray array];
    for (int i=0; i<count; i++) {
        Method method = methodList[i];
        SEL sel = method_getName(method);
        [arr addObject:NSStringFromSelector(sel)];
    }
    free(methodList);
    
    NSLog(@"%@", cls);
    NSLog(@"%@", arr);
}

获得变量数组(ivarList)

Ivar* class_copyIvarList(Class cls, unsigned int* outCount) 
var count:UInt32 = 0
let result = class_copyIvarList(UIGestureRecognizer.self, &count)!
for i in 0..<count{
    let namePointer = ivar_getName(result[Int(i)])!
    let name = String(cString: namePointer)
    print(name)
}

相关文章

  • 附录:runtime函数

    获得对象的类名 获得方法数组(methodList) 获得变量数组(ivarList)

  • 附录

    附录A C语言中的操作符总表 附录B C99 VS C89 附录C C89 VS K&R C 附录D 标准库函数 ...

  • go runtime包的使用

    runtime.GOMAXPROCS函数 通过runtime.GOMAXPROCS函数,应用程序何以在运行期间设置...

  • iOS开发经验(14)-runtime

    目录 回顾类&对象&方法 OC的动态特性 Runtime详解 应用场景 Runtime缺点及Runtime常用函数...

  • 运行时简单介绍

    runtime : runtime:运行时,操作类的函数是以class_开头,操作成员变量的函数以ivar_开头。...

  • iOS @Property属性之动态添加

    runtime 实现 首先要引入 ,需要利用runtime.h文件的两个函数完成 ...

  • runtime

    Runtime 一、消息机制 类 ——> SEL(方法编号) ——> IMP(函数指针) ——> 方法(函数) *...

  • Runtime底层原理--动态方法解析、消息转发源码分析

    了解了Runtime函数含义,我们就可以直接使用Runtime的API了,那接下来继续探究Runtime的源码,经...

  • Swift5.1学习随笔之多态

    多态的实现原理: OC:Runtime C++:虚表(虚函数表) Swift:纯Swift没有Runtime,更加...

  • 字符与字符串处理

    CLR common language runtime windows下:ANSI函数只是一个对Unicode函数...

网友评论

      本文标题:附录:runtime函数

      本文链接:https://www.haomeiwen.com/subject/orioahtx.html