每一个不曾起舞的日子都是对生命的辜负。
其实看了一些别人讲的教程,对Runtime的认识还是很模糊,希望之后多实践可以加深了解
定义
最终执行代码
Runtime中的消息
_cmd关键字
OC下代码:[tableview cellForRowAtIndexPath:indexPath]
在编译时Runtime会转换成【发送消息】objc_msgSend(tableview, @selector(cellForRowAtIndexPath:), indexPath);
常见方法
unsigned int count;
获取属性列表
objc_property_t *propertyList = class_copyPropertyList([self class], &count);
获取方法列表
Method *methodList = class_copyMethodList([self class], &count);
获取成员变量列表
Ivar *ivarList = class_copyIvarLis([self class], &count);
获取协议列表
__unsafe_unretained Protocol **protocolList = class_copyProtocolList([self class], &count);
有一个Person类,和创建的xiaoming对象,有test1、test2两种方法
获取类方法
|
|
获取实例方法
|
|
增添方法
class_addMethod(xiaomingClass, sel, method_getImplementation(method), method_getTypeEncoding(method));
替换原方法
class_replaceMethod(toolClass, sel, method_getImplementation(method), method_getTypeEncoding(method));
交换两个方法
method_exchangeImplementation(method1,method2);
功能作用
参数概念
objc_msgSend_stret
发送返回值为结构体的消息objc_msgSend_fpret
发送返回值为浮点类型的消息objc_msgSend_fp2ret
发送返回值为浮点类型的消息objc_msgSend函数
IMP
关联对象