ZZAutoDescription 1.1.0

ZZAutoDescription 1.1.0

测试测试过的
Lang语言 Obj-CObjective C
授权 MIT
发布最后发布2016年6月

IvanMac 维护。



  • 作者:
  • Ivan Zezyulya

关于

ZZAutoDescription 是一组方便的类别,用于打印您自己的对象,以及 Objective-C 的标准对象和集合。让我们快速比较一下。给定以下数据集

NSArray *array = @[ @"Hello!",
                    @"123",
                    @(123),
                    @(123LL),
                    @(123.0f),
                    @(3.14159f),
                    @(3.14159),
                    @{@"id1": @[@1, @2, @3],
                      @"id2": @[@4, @5, @6]},
                    @"Good bye!" ];

以下是如何使用标准 [array description] 打印的

(
    "Hello!",
    123,        // note that this is a string
    123,        // this is an integer
    123,        // this is long long
    123,        // this is float
    "3.14159",  // this is float
    "3.14159",  // this is double
        {
        id1 =         (
            1,
            2,
            3
        );
        id2 =         (
            4,
            5,
            6
        );
    },
    "Good bye!"
)

以及 ZZAutoDescription 对相同数据的打印

[
  "Hello!",
  "123",    // string looks like a string
  123,
  123LL,    // long long is distinguishable from integer
  123f,     // as a float
  3.14159f,
  3.14159,  // and as a double
  {
    "id1" = [
      1,
      2,
      3
    ],
    "id2" = [
      4,
      5,
      6
    ]
  },
  "Good bye!"
]

ZZAutoDescription 还可以自动打印对象的属性。请参阅演示以获取更多信息(您可以通过使用方便的 pod try 命令快速查看演示,例如 pod try ZZAutoDescription

使用方法

#import "ZZAutoDescription.h.h"

假设您有一个对象或一个对象集合,只需调用

[object zz_autoDescription]

或者

[collection zz_autoDescription]

也可以通过在对象的实现部分中添加一个 ZZ_AUTO_DESCRIPTION 宏,使您希望的对象自动进行 autodescribe。

@interface Product: NSObject
<list of your properties>
@end;

@implementation Product
ZZ_AUTO_DESCRIPTION
@end

它覆盖了 description 方法,因此现在您可以使用对象的默认方式使用 NSLog,例如,它将被格式化打印。

安装

作者

Ivan Zezyulya,

授权

ZZAutoDescription 在 MIT 授权下可用。有关更多信息,请参阅 LICENSE 文件。