美文网首页
Runtime-(三)消息传递机制

Runtime-(三)消息传递机制

作者: 码小六 | 来源:发表于2018-11-02 23:19 被阅读0次

我们知道在OC中,所有的方法调用最终都会转换成objc_msgSend形式的方法调用。如下图:

Xnip2018-10-24_16-31-38.png

而对于调用父类的方法,用的是另一个方法objc_msgSendSuper

Xnip2018-10-24_16-40-01.png

我们再来看看super的结构体

/// Specifies the superclass of an instance.
/// 指定实例的超类。
struct objc_super {
    /// Specifies an instance of a class.
    /// 指定类的实例
    __unsafe_unretained _Nonnull id receiver;

    /// Specifies the particular superclass of the instance to message.
#if !defined(__cplusplus)  &&  !__OBJC2__
    /* For compatibility with old objc-runtime.h header */
    __unsafe_unretained _Nonnull Class class;
#else
    __unsafe_unretained _Nonnull Class super_class;
#endif
    /* super_class is the first class to search */
};

我们重点关注__unsafe_unretained _Nonnull id receiver;这个对象,super是一个编译器关键字,经过编译器编译后,会被解析成objc_super类型的结构体指针,而其中的receiver成员变量就指向当前的对象。

我们再回来来看看方法传递的流程

Xnip2018-10-24_16-59-46.png

我们会在方法缓存章节中详细说明系统是如何进行方法缓存的

相关文章

  • Runtime-(三)消息传递机制

    我们知道在OC中,所有的方法调用最终都会转换成objc_msgSend形式的方法调用。如下图: 而对于调用父类的方...

  • Runtime-消息传递的流程机制

    缓存查找流程 根据给定的方法选择器SEL,来查找bucket_t中具体的方法实现IMP bucket_t是方法缓存...

  • runtime-消息传递与转发机制

    参考文章:继承自NSObject的不常用又很有用的函数【重点推荐】Objective-C Runtime 1小时入...

  • 底层技术以及runtime分享

    https://minilv.github.io/2019/03/17/Runtime-消息机制土味讲解/?nsu...

  • 3-2 runtime-消息传递机制

    经典错误:unrecognized selector sent to instance 0x60400000e3e...

  • Runtime-消息机制

    Objective-C是一门动态语言,类型的判断、类的成员变量、方法的内存地址都是在程序的运行阶段才最终确定,并且...

  • runtime-消息机制

    从异常说起 我们都知道,在iOS中存在这么一个通用类类型id,它可以用来表示任何对象的类型 —— 这意味着我们使用...

  • runtime-消息机制

    OC方法调用,其实都是转换为objc_msgSend函数调用objc_msgSend的执行流程可以分为3大阶段:消...

  • Runtime-原理

    runtime初探对象与方法的本质runtime-消息发送runtime-动态方法解析runtime-消息转发 r...

  • iOS开发-runtime-消息传递和转发机制

    objective-c是一门动态语言,动态语言的特点就是方法的调用是在运行时(runtime)而不是编译时。 C语...

网友评论

      本文标题:Runtime-(三)消息传递机制

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