Runtime一 之获取对象的所有属性/方法

直接上代码

#import@implementation NSObject (XXOOProperty)

/* 获取对象的所有属性和属性内容 */

- (NSDictionary *)getAllPropertiesAndVaules
{
  NSMutableDictionary *props = [NSMutableDictionary dictionary];
  unsigned int outCount, i;
  objc_property_t *properties =class_copyPropertyList([self class], &outCount);
  for (i = 0; i

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

- (NSArray *)getAllProperties
{
  u_int count;
  objc_property_t *properties  =class_copyPropertyList([self class], &count);
  NSMutableArray *propertiesArray = [NSMutableArray arrayWithCapacity:count];
  for (int i = 0; i < count ; i++)
  {
    const char* propertyName =property_getName(properties[i]);
    [propertiesArray addObject: [NSString stringWithUTF8String: propertyName]];
  }
  free(properties);
  return propertiesArray;
}

/* 获取对象的所有方法 */

-(void)getAllMethods
{
  unsigned int mothCout_f =0;
  Method* mothList_f = class_copyMethodList([selfclass],&mothCout_f);
  for(int i=0;i

你可能感兴趣的:(Runtime一 之获取对象的所有属性/方法)