Stephen Touset Stephen Touset - 4 years ago 183
Objective-C Question

Forward-declare enum in Objective-C

I'm having trouble with enum visibility in an Objective-C program. I have two header files, and one defines a

typedef enum
. Another file needs to use the
'd type.

In straight C, I would simply
the other header file, but in Objective-C, it's recommended not to use
between header files, instead using forward
declarations as needed. However, I can't figure out how to forward-declare an enumeration type.

I don't need the actual enumerated values, except in the corresponding
implementation file, where I can safely
away. So how can I get the
typedef enum
to be recognized in the header?

Answer Source

Go ahead and use #import. The only reason people recommend to use @class when possible is because it makes your code slightly faster to compile. However, there is no issue with #importing one .h file from another. In fact, you need to do this when extending another class.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download