获取对象的所有属性&&获取对象的所有方法

#import <objc/runtime.h>

@implementation NSObject (PropertyListing)

/* 获取对象的所有属性 */

- (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);

}

获取对象的所有属性&&获取对象的所有方法

时间: 2024-07-29 22:26:25

获取对象的所有属性&&获取对象的所有方法的相关文章

怎样获取对象的所有属性

使用Object.keys()可以获取对象本身所有的可遍历属性; 使用Object.getOwnPropertyNames()可以获取对象本身所有属性, 不管是否可遍历; 使用for...in...循环可以获取对象所有可遍历属性, 包括本身的属性和继承的属性; 使用下面的函数可以获取对象的所有属性, 不管是本身还是继承, 不管是可遍历还是不可遍历: function inheritedPropertyNames(obj) { var props = {}; while(obj) { Object

Java 获取对象的所有属性及其对应的值

利用反射获取对象的所有属性及对应的值 1.获取属性名数组 private static String[] getFiledName(Object o) { Field[] fields = o.getClass().getDeclaredFields(); String[] fieldNames = new String[fields.length]; for (int i = 0; i < fields.length; i++) { fieldNames[i] = fields[i].getN

Javascript 笔记与总结(2-9)获取运行时的 style 对象

获取内存中(正在渲染)的 style 的值(非内联 style,obj.style 只能获得内联 style 的值),可以用 obj.currentStyle(低版本 IE 和 Opera 支持)和 window.getComputedStyle(IE9 以及 标准浏览器支持)来获取. window.getComputedStyle 的格式是 window.getComputedStyle(obj,伪元素) 第一个参数是要要获取计算后的样式的目标元素 第二个参数是期望的伪元素,如"after&q

是用JDBC从数据库中获取数据并以java对象返回

/** * * @param c * for example Person.class * @param primaryKeys * primaryKeys为主键,参数顺序和表中保持一致 如果id, name 为主键 类名为Person 则 getEntity(Person.class,1,"name") * @return */ public static Object getEntity(Class c, Object... primaryKeys) { PreparedState

数组对象元素的添加,String对象,BOM对象以及文档对象的获取

数组对象的删除有三种方法: pop();        //移除最后一个元素并返回该元素值shift();      //移除最前一个元素并返回该元素值,数组中元素自动前移splice(0,2); //删除从指定位置deletePos开始的指定数量deleteCount的元素,数组形式返回所移除的元素通过这三种方法我们可以将数组中的元素按进行删除 var del = ["aa",23,345,56,34,"bb"]; var del_last = del.pop()

基于Spring DM管理的Bundle获取Spring上下文对象及指定Bean对象

在讲述服务注册与引用的随笔中,有提到context.getServiceReferences()方法,通过该方法可以获取到OSGI框架容器中的指定类型的服务引用,从而获取到对应的服务对象.同时该方法还可以通过Bundle-SymbolicName名称获取到该Bundle中的Spring上下文对象,同样根据Spring上下文对象,我们也可以很好的获取到对应服务对象(服务对象,就是Spring中的一个Bean对象) String callName = "com.sample.service.IHel

ios 获取按钮所在的cell对象, 注意:ios8 ios7 获取cell对象的区别

ios7 : ios7 下 button.superview.superview .superview 是获取按钮所在的cell  NSLog(@"2: cell ---- %@", button.superview.superview.superview); 2014-10-07 10:23:55.583 NeiHanShe[1407:60b] 2: cell ---- <RadioCell: 0x155849d0; baseClass = UITableViewCell; f

解决javaassist 出现的类没找到异常ClassNotFoundException,获取工程下任意class对象

项目中要对工程下任意class文件进行解析,但是使用javaassist中经常出现类没找到异常.当然最主要的还是ClassPool()没找到这东西,而搜索范围是整个项目的class, 所以就做了一个处理,通过,项目下的classpath这个文件,获取所有jar路径在,再通过文件递归搜索获取所有java编译后的class文件路径,将所有路径都添加到对象池中.当然这一步是很费时的,所以最好只初始化一次. /*** * * 静态存储 */ private static ClassPool pool;

javascript获取json对象的key名称的两种方法

javascript获取json对象的key名称的两种方法 数据处理中,你可能接收到一个不确定内容格式的json对象,然后要把key的值提取出来.今天试过两种可以提取json key的方法,均可以正常工作. 先看第一种方法 jsonObj = { Name: 'richard', Value: '8' }for (key in jsonObj){ console.log(key); //add your statement to get key value} 结果 NameValue 第二种方法