美文网首页
Description格式化

Description格式化

作者: 靠北的北 | 来源:发表于2020-08-17 11:32 被阅读0次

runtime class 属性

// ...
#import <objc/runtime.h>
// ...

- (NSString *)description{
   unsigned int count ,i;
   objc_property_t *propertyArray = class_copyPropertyList([self class], &count);
   NSMutableDictionary *tmpDic = [NSMutableDictionary dictionary];
   for (i = 0; i < count; i++) {
       objc_property_t property = propertyArray[i];
       NSString *proKey = [NSString stringWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
       id proValue = [self valueForKey:proKey];
       
       if (proValue) {
           [tmpDic setObject:proValue forKey:proKey];
       } else {
           [tmpDic setObject:@"" forKey:proKey];
       }
   }
   free(propertyArray);
   return  [NSString stringWithFormat:@"%@: %p, \n%@", [self class], self, tmpDic];
}

相关文章

  • Description格式化

    runtime class 属性

  • 日期、时间格式化封装

    日期、时间格式化封装 /***@description:格式化日期时间*@param{string}formatD...

  • js格式化日期

    /** @description 格式化日期 @param {Date|Number|String} date @...

  • javascript Date format 时间格式化

    title: Date时间格式化date: 2021-06-09description: 这是可以用于项目开发中的...

  • description

    description Returns a string that represents the contents...

  • description

    一般打印一个对象的时候输出的是对象名称和地址如果想打印对象里面的具体成员变量的值就需要重写description方法

  • Description

    简述description description方法是NSObject类的一个实例方法,因此所有的Object-...

  • OBJDescription 格式化输出 解决字典数组自定义类的

    格式化输出 最近在看52个方法这本书,其中有一个方法讲的就是关于编写Description方法的,这个方法我之前也...

  • description重写

    定义了对象的打印格式 是系统提供的方法 通常该方法对我们是隐身的 但是NSLog打印当前类对象时,该方法会被调用/...

  • 多态 description

    多态是某一种事物的多种形态多态的条件 有继承关系 父类指针指向子类 子类重写父类方法 description注意点...

网友评论

      本文标题:Description格式化

      本文链接:https://www.haomeiwen.com/subject/bdafjktx.html