iOS 获取类的属性,方法,属性类型

头文件中导入#import 

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移动开发)