4

我正在使用枚举,如下所示:

typedef NS_ENUM(NSInteger, MyURLType) {
    MyURLType1,
    MyURLType2,
    MyURLType3
};

当我尝试比较或识别类型时出现问题:

if (type == MyURLType2)

在and的情况下我收到"Incompatible integer to pointer conversion"警告(不是在 的情况下)。我在声明中做错了吗?有任何想法吗?MyUrlType2MyUrlType3MyURLType1

谢谢!

4

3 回答 3

6
于 2013-08-30T08:21:54.400 回答
0

why not define type as an int? Then, you can compare the ints. Simple and clean solution.

int type = MyURLTypeX; 

will allow you to do

if (type == MyURLType2) since they're both ints.

How is it possible no one has suggested this yet?

于 2015-08-07T17:00:08.363 回答
-1

was just researching this, but looks like another option is to cast the enum:

if (type == (MyURLType *) MyURLType2)

于 2014-08-20T21:07:33.717 回答