一、前言
话不多少,直接进入正题;Objc_message其实包含runtime;当你导入头文件#import<objc/message.h>的时候实际上也导入(message头文件包含导入)runtime头文件,因此使用message不需要再次导入runtime
二、OC是消息发送机制,因此调用一个方法的方式有很多eg:

提示:如果调用message方法没有参数提示,那么需要设置一下 项目->build settings ->搜索msg(enable strict checking of objc_msgSend Calls) ->将其设置为NO 这样就有提示啦
三、利用runtime进行系统方法替换

以上仅是部分关键代码,附件demo:探索Objc_message
三、常见的函数
Ivar * class_copyIvarList(<#Class _Nullable __unsafe_unretained cls#>, <#unsigned int * _Nullable outCount#>) : 获得某个类内部的所有成员变量
Method * class_copyMethodList(<#Class _Nullable __unsafe_unretained cls#>, <#unsigned int * _Nullable outCount#>) : 获得某个类内部的所有方法
Method class_getInstanceMethod(<#Class _Nullable __unsafe_unretained cls#>, <#SEL _Nonnull name#>) : 获得某个实例方法(对象方法,减号-开头)
Method class_getClassMethod(Class _Nullable cls, SEL _Nonnull name) : 获得某个类方法(加号+开头)
method_exchangeImplementations(<#Method _Nonnull m1#>, <#Method _Nonnull m2#>) : 交换2个方法的具体实现
objc_msgSend(<#id _Nullable self#>, <#SEL _Nonnull op, ...#>):发送消息
网友评论