PDA

View Full Version : Equivalent of @class for a type?




RossOliver
Jul 3, 2008, 02:09 AM
Hey,

I have two classes, ClassA and ClassB. In the ClassB header I have:


typedef enum_AType
{
ATypeA,
ATypeB,
ATypeC
} AType;


In the ClassA header I have a method prototype:


-( AType )someMethod;


This set up only works if I include the ClassB header file in the ClassA header file - which I don't want to do (since it's against convention). I want the ClassB header to be included in the ClassA .m file. Do I need to do a @class equivalent for the type?

Cheers



robbieduncan
Jul 3, 2008, 02:47 AM
There is not equivalent to a @class for an enum. Simply stick the typedef in a new .h file and include this in both of the class .h files.

RossOliver
Jul 3, 2008, 12:02 PM
There is not equivalent to a @class for an enum. Simply stick the typedef in a new .h file and include this in both of the class .h files.

Ah, I was hoping for a more elegant solution - but if one doesn't exist I guess I have to put it in a separate header file or include ClassB.h in ClassA.h...

Cheers

[edit]

Out of interest - Cocoa conventions state always to @class in the header and #include in the source, but looking through the UIKit framework there are a lot of #include's in the header files:


UIDatePicker.h:

#import <Foundation/Foundation.h>
#import <UIKit/UIControl.h>
#import <UIKit/UIKitDefines.h>

UILabel.h:

#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIView.h>
#import <UIKit/UIStringDrawing.h>
#import <UIKit/UIKitDefines.h>


Any particular reason for this?