码迷,mamicode.com
首页 > 其他好文 > 详细

runtime 总结(原创)

时间:2016-06-03 12:40:21      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

runtime实际运用场景

1.使用runtime可以读取iOS系统类有哪些属性,并通过kvc修改或者读取其值。

Ivar *class_copyIvarList(Class cls, unsigned int *outCount)  读取某个类所有属性和成员变量

objc_property_t *class_copyPropertyList(Class cls, unsigned int *outCount) 读取某个类所有属性

const char *ivar_getName(Ivar v)  返回属性或成员变量的名字 同理 property_getName

 

2.替换已有函数或方法,同理替换属性

IMP class_replaceMethod(Class cls, SEL name, IMP imp, 

                                    const char *types)  替换函数或方法

void class_replaceProperty(Class cls, const char *name, const objc_property_attribute_t *attributes, unsigned int attributeCount) 替换属性

SEL

这个是方法名称的描述。

IMP

这个是具体的方法的地址。

NSObject 类中的methodForSelector:方法就是这样一个获取指向方法实现IMP 的指针,methodForSelector:返回的指针和赋值的变量类型必须完全一致,包括方法的参数类型和返回值类型。 // SEL --> IMP

 

3.动态挂载对象

 

runtime 总结(原创)

标签:

原文地址:http://www.cnblogs.com/iOSJason/p/5555802.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!