/**
*获取对象的所有属性
*/
- (NSArray *)getAllPropertis {
NSMutableArray *array = [NSMutableArray array];
unsigned int count;
objc_property_t *properties = class_copyPropertyList(self, &count); //获取属性列表
for (long i = 0; i < count; i++) {
objc_property_t property = properties[i];
NSString *propertyName = [NSString stringWithCString:property_getName(property) encoding:NSUTF8StringEncoding]; //将属性转化为NSString类型
[array addObject:propertyName];
}
return array;
}
/**
*获取对象的所有方法
*/
-(NSArray*)getAllMethodList
{
unsigned int methodCount = 0;
Method* methodList = class_copyMethodList([self class],&methodCount);
NSMutableArray* array = [NSMutableArray arrayWithCapacity:methodCount];
for(int i = 0; i<methodCount; i++)
{
Method tempMethod = methodList[i];
IMP imp = method_getImplementation(tempMethod); //函数指针
SEL name = method_getName(tempMethod); //选择子
const char* cName = sel_getName(method_getName(tempMethod));
int argumentsCount = method_getNumberOfArguments(tempMethod); //方法的参数个数
const char* encoding = method_getTypeEncoding(tempMethod); //编码方式
NSString* strName = [NSString stringWithUTF8String:cName];
[array addObject:strName];
}
free(methodList);
return array;
}