获得对象的方法以及属性
来源:互联网 发布:linux怎么显示中文 编辑:程序博客网 时间:2024/05/20 15:10
所谓的反射机制:指的是程序在运行时能够获取自身的信息。
/* 获取对象的所有属性 */
- (NSDictionary *)properties_aps{ NSMutableDictionary *props = [NSMutableDictionarydictionary]; unsigned int outCount, i; objc_property_t *properties = class_copyPropertyList([self class], &outCount); for (i = 0; i< outCount; i++) { objc_property_t property = properties[i]; const char* char_f =property_getName(property); NSString *propertyName = [NSStringstringWithUTF8String:char_f]; id propertyValue = [selfvalueForKey:(NSString *)propertyName]; if (propertyValue) [props setObject:propertyValue forKey:propertyName]; } free(properties); return props; }
/* 获取对象的所有方法 */
-(void)printMothList{ unsigned int mothCout_f =0; Method* mothList_f = class_copyMethodList([self class],&mothCout_f); for(int i=0;i<mothCout_f;i++) { Method temp_f = mothList_f[i]; IMP imp_f = method_getImplementation(temp_f); SEL name_f = method_getName(temp_f); const char* name_s =sel_getName(method_getName(temp_f)); int arguments = method_getNumberOfArguments(temp_f); const char* encoding =method_getTypeEncoding(temp_f); NSLog(@"方法名:%@,参数个数:%d,编码方式:%@",[NSStringstringWithUTF8String:name_s], arguments, [NSStringstringWithUTF8String:encoding]); } free(mothList_f);}
阅读全文
0 0
- 获得对象的方法以及属性
- JS 输出对象的属性以及方法
- JS获得一个对象的所有属性和方法
- JS获得一个对象的所有属性和方法
- python 获得对象的所有属性和方法
- JS获得一个对象的所有属性和方法实例
- 几种获得LayoutInflater对象的方法以及区别
- Android的Application对象使用以及获得方法
- 理解对象以及对象的属性、方法、事件
- window对象的常用属性和方法以及对象
- 理解对象以及对象的属性、方法、事件
- 获得javascript中对象的所有方法名和属性名的方法
- window对象的所有属性以及方法(不包括netsape)
- ASP Session对象的集合以及属性方法事件
- ASP Session对象的集合以及属性方法事件
- 浅谈对象oop的属性和方法以及区别
- 获得对象的另一种方法
- 获得request对象的方法
- GCC 编译器的一些基本操作
- 微信小程序架构分析 (中)
- leetcode Algorithms 2. Add Two Numbers
- 最大无法表示成px+qy(x>=0,y>=0)的数
- core核心模块--改变图像对比度和亮度
- 获得对象的方法以及属性
- 使用easyui增加切换子视图
- stl->deque
- 14 orangepi 内核里控制IO口
- 常用的正则表达式判断手机号邮箱等
- 四种实体类类型概念:VO、DTO、DO、PO
- 过滤IE浏览器版本
- 易错点——queue中的入队出队
- 39、平衡二叉树