Warning: Incompatible integer to pointer conversion when using NS_ENUM types

enums, ios, objective-c

Solution

From your comment

Yes, I am using MyURLType *type = MyURLTypeX

Then `type` is not of type `MyURLType`, it is of type `pointer to MyURLType`.

if (type == MyURLType2)

Here you are comparing a pointer type (`type`) to an integer type (`MyURLType`). If the integer type is `0` it doesn't generate a warning, because it could be a check for `NULL`.

You either need to declare `type` as a simple `MyURLType` (`MyURLType type =…`) or dereference `type` when comparing (`if (*type == MyURLType2)`).

Problem

I am using an enum, something like this: ``` typedef NS_ENUM(NSInteger, MyURLType) { MyURLType1, MyURLType2, MyURLType3 }; ``` The problem appears when I try to compare or identify the type: ``` if (type == MyURLType2) ``` I am getting a `"Incompatible integer to pointer conversion"` warning in the case of `MyUrlType2` and `MyUrlType3` (not in the case of `MyURLType1`). Am I doing anything wrong in the declaration? Any ideas? Thanks!

Original source