枚举应该以什么格式打印? %什么?
这行代码导致编译器报错并进入调试模式
NSLog(@"Attacker card: %@", [attackerCard suit]);
我想知道这是否是由于西装是一个enum
值声明为
@property (assign) Suit suit;
其中Suit
被声明为
typedef enum {
CLUBS, DIAMONDS, HEARTS, SPADES
} Suit;
Am我的格式有问题,或者问题出在其他地方?
This line of code causes compiler to complain and enter a debug mode
NSLog(@"Attacker card: %@", [attackerCard suit]);
I wonder whether it is due to the fact that suit is an enum
value declared as
@property (assign) Suit suit;
Where Suit
is declared as
typedef enum {
CLUBS, DIAMONDS, HEARTS, SPADES
} Suit;
Am i doing something wrong with the format or, the problem lies elsewhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
枚举类型的具体大小是实现定义的,但它始终是整数类型,因此
%d
在大多数情况下都可以工作。如果您需要它非常强大,您需要测试sizeof(Suit)
并基于此选择一种格式。The specific size of an enumerated type is implementation defined but it's always an integer type, so
%d
will work most of the time. If you need it to be very robust, you'll want to testsizeof(Suit)
and choose a format based on that.