zoukankan      html  css  js  c++  java
  • iOS之runtime

    runtime
        简介:
            1.通过 Objective-C
                直接编写 Objective-C 代码 在程序运行期间会自动将代码转换成相应的结构体和函数。
            2.通过NSObject的方法 NSObject方法定义了许多方法用来直接调用Runtime里面的方法
                isKindOfClass:;isMemberOfClass:
                respondsToSelector:
                conformsToProtocol:
                methodForSelector:
            3.直接操作runtime方法
                runtime系统是一个C语言静态库,它拥有许多函数和结构体数据 需要导入<objc/runtime.h>
        Class:Class结构体主要存储类的实例变量和实例方法
            OC编译之后 类是由Class表示 实际指向objc_class结构体
            isa:指向metaClass(元类) 存储类的类方法和类变量
            super_class:指向父类
            methodLists:该类的方法列表
            ivars:存储类的成员变量的信息
        Method:是runtime内部定义的函数,用来代表一个方法
            介绍:
                SEL method_name:方法选择器的名字 用来区分方法的ID
                    获取SEL的方法
                        1、@selector()
                        2、NSSelectorFromString()
                        3、sel_registerName函数
                char *method_types:类型 存储着方法的参数类型和返回值类型
                IMP method_imp:指向此方法的具体实现 指向的方法在内存中的位置
        Ivar:实例变量
     
        使用
            获取类名:class_getName
            获取父类名:class_getSuperclass
            获得实例变量的大小:class_getInstanceSize
     
            获得方法名:method_getName
            获得方法的实现:method_getImplementation
            获得方法的参数 和返回值类型的字符串:method_getTypeEncoding
            获得方法参数的个数:method_getNumberOfArguments
            设置实现方法:method_setImplementation
            交换两个方法:method_exchangeImplementations
            发送消息:objc_msgSend
            添加重写 一个方法:class_addMethod
            替换方法:class_replaceMethod
            获得实例方法:class_getInstanceMethod
            获得所有实例方法:class_copyMethodList
            获得方法的实现IMP:class_getMethodImplementation
            查询是否响应某个方法:class_respondsToSelector 
  • 相关阅读:
    雪花算法 Java 版
    Java 生成有序 UUID
    Spring Boot 2 集成 Swagger
    Spring Cloud 学习 (九) Spring Security, OAuth2
    Spring Cloud 学习 (八) Spring Boot Admin
    Spring Cloud 学习 (七) Spring Cloud Sleuth
    Spring Cloud 学习 (六) Spring Cloud Config
    原创:全排列非递归算法:微软给出的算法
    原创:协同过滤之spark FP-Growth树应用示例
    转载:scala中的:++::::::
  • 原文地址:https://www.cnblogs.com/liuzhi20101016/p/5463737.html
Copyright © 2011-2022 走看看