检查是否存在目标c enum [英] Check if a objective c enum exists
问题描述
我为按钮ID预定了枚举:
I have predefined enum for buttons IDs:
typedef enum
{
button1ID = 407,
button2ID = 999,
button3ID = 408,
button4ID = 409,
} TOP_MENU_BUTTON_TYPE;
我需要查明我收到的ID是否在枚举中被定义。我怎样才能做到这一点?类似于:
I need to find out if the ID I recieve is defiened in the enum. How can I do that? Something like:
if(id in TOP_MENU_BUTTON_TYPE)
推荐答案
如果我清楚地理解你的问题,那么这对你有帮助..
If I understand your question clearly, then this would be helpful to you..
不要单独使用 enum
,而应该尝试使用 struct
,这是@Richard的回答将帮助您如何做到这一点。
Instead of using enum
alone, you should try that with struct
and here it is an answer by @Richard will help you how to do that.
https:// stackoverflow.com/a/10305425/1083859
在上面的链接中,他解释了如何使用动态枚举
带有 struct
的值,还可以迭代
要查找的值。我想你会有个主意。
In the above link, he explains how to use a dynamic enum
values with struct
and also you can iterate
the values to find out. I think you will get an idea.
这篇关于检查是否存在目标c enum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!