iOS 获取类的属性,方法,属性类型
2017-02-13 14:17
330 查看
头文件中导入#import <objc/runtime.h>
1. 获取类的属性
+(NSArray *)propertyList {
unsigned int count = 0;
objc_property_t *propertyList = class_copyPropertyList([self class] , &count);
NSMutableArray *array = [NSMutableArray arrar];
for(int i = 0 ; i < count ; i ++) {
objc_property_t property = propertyList[i];
const char *propertyChar = property_getName(property);
NSString *propertyName = [NSString stringWithUTF8String:propertyName];
[array addObject:propertyName];
}
free(propertyList);
return array.copy;
}
2. 获取类的属性类型
+ (NSArray *)propertyType {
unsigned int count = 0;
objc_property_t *propertyList = class_copyPropertyList([self class] , &count);
NSMutableArray *array = [NSMutableArray arrar];
for(int i = 0 ; i < count ; i ++) {
objc_property_t property = propertyList[i];
const char *propertyChar = property_getAttributes(property);
NSString *propertyName = [NSString stringWithUTF8String:propertyName];
[array addObject:propertyName];
}
free(propertyList);
return array.copy;
}
3.获取类的方法
+ (NSArray *)funcList {
unsigned int count = 0;
Method *methodList = class_copyMethodList([self class] , &count);
NSMutableArray *array = [NSMutableArray array];
for(int i = 0 ; i < count ; i++) {
Method method = methodList[i];
SEL selector = method_getName(method);
NSString *funcName = NSStringWithSelector(selector);
[array addObject:funcName];
}
free(methodList);
return array.copy;
}
1. 获取类的属性
+(NSArray *)propertyList {
unsigned int count = 0;
objc_property_t *propertyList = class_copyPropertyList([self class] , &count);
NSMutableArray *array = [NSMutableArray arrar];
for(int i = 0 ; i < count ; i ++) {
objc_property_t property = propertyList[i];
const char *propertyChar = property_getName(property);
NSString *propertyName = [NSString stringWithUTF8String:propertyName];
[array addObject:propertyName];
}
free(propertyList);
return array.copy;
}
2. 获取类的属性类型
+ (NSArray *)propertyType {
unsigned int count = 0;
objc_property_t *propertyList = class_copyPropertyList([self class] , &count);
NSMutableArray *array = [NSMutableArray arrar];
for(int i = 0 ; i < count ; i ++) {
objc_property_t property = propertyList[i];
const char *propertyChar = property_getAttributes(property);
NSString *propertyName = [NSString stringWithUTF8String:propertyName];
[array addObject:propertyName];
}
free(propertyList);
return array.copy;
}
3.获取类的方法
+ (NSArray *)funcList {
unsigned int count = 0;
Method *methodList = class_copyMethodList([self class] , &count);
NSMutableArray *array = [NSMutableArray array];
for(int i = 0 ; i < count ; i++) {
Method method = methodList[i];
SEL selector = method_getName(method);
NSString *funcName = NSStringWithSelector(selector);
[array addObject:funcName];
}
free(methodList);
return array.copy;
}
相关文章推荐
- ios获取未知类所有属性和方法
- iOS 获取屏幕的属性和宽度的方法
- 获取iOS项目名称及版本号以及网络类型的方法
- java反射遍历实体类属性和类型,并赋值和获取值的简单方法
- java反射遍历实体类属性和类型,并赋值和获取值的简单方法
- IOS获取网络类型方法分析
- IOS获取plist文件属性值的方法
- extjs中超级厉害获取组件的方法Ext.ComponentQuery.query(),根据组件类型(xtype属性)获取组件。
- iOS运行时runtime获取私有属性和强制更改私有属性,以及获取私有方法
- iOS - 3种方法获取设备硬件类型:
- IOS获取plist文件属性值的方法
- iOS获取plist文件属性值的方法
- 【获取iOS设备类型与系统版本号】结构体utsname与uname方法的使用
- 4.2、JS——var 数据类型 节点标签属性操作 动态获取方法
- [ios]objective-c 反射获取类的属性的方法
- iOS 获取类的全部属性和全部方法 +(用例拓展:MVC的数据解析==数据映射)
- IOS获取网络类型方法分析
- iOS获取网络类型的方法汇总
- iOS的runtime获取类的属性的数据类型
- iOS开发-获取属性和方法