使用描述打印结构

Cha*_*den 2 cocoa struct objective-c nslog

我想知道是否可以使用descriptionCocoa框架中的函数来记录a的内容struct.例如:

    typedef struct {float a,b,c;}list;
    list testlist = {1.0,2.5,3.9};
    NSLog(@"%@",testlist); //--> 1.0,2.5,3.9
Run Code Online (Sandbox Code Playgroud)

Way*_*man 6

否.description消息是NSObject协议中找到的方法,因此根据定义,必须是对象.但是,使用LOG_EXPR()宏可以更方便地进行日志调试.这将采用对象和结构:

LOG_EXPR(testlist);

哪个会输出:

testlist = {1.0,2.5,3.9};

这段代码可以在这里找到.