打印枚举的字符串表示形式,NSLog [英] Print string representation of an enum, NSLog

查看:144
本文介绍了打印枚举的字符串表示形式,NSLog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试NSLog我有一些枚举。例如,这段代码打印枚举的整数表示,但是我希望它输出实际的字符串名称,在这种情况下为MON。我该怎么做?

  #import< Foundation / Foundation.h> 
int main(void)
{
typedef枚举{
SUN,
MON,
TUES
} DAYS;

DAYS d = MON;
NSLog(@%@,d);
return 0;
}


解决方案

LLDB调试器将显示字符串标识符因此,不用使用NSLog,您可以使用一个带有调试器命令操作的断点(在您的情况下为pd),并在断开点后自动继续进行评估。



您可以通过右键单击蓝色标记来配置断点。


I am trying to NSLog some enums I have. For example this piece of code prints the integer representation of the enum, but I want it to output the actual string name, in this case MON. How can I do that?

#import <Foundation/Foundation.h>
int main(void)
{
    typedef enum {
        SUN,
        MON,
        TUES
    } DAYS;

  DAYS d = MON;
  NSLog(@"%@", d);
  return 0;
}

解决方案

The LLDB debugger will show the string identifiers. So instead of using NSLog you could use a breakpoint with a debugger command action ("p d" in your case) and set the breakpoint to automatically continue after evaluating.

You can configure a breakpoint by right-clicking on the blue marker.

这篇关于打印枚举的字符串表示形式,NSLog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆