Equivalent of @class for a type?

Discussion in 'Mac Programming' started by RossOliver, Jul 3, 2008.

  1. RossOliver macrumors regular

    Joined:
    Nov 6, 2006
    #1
    Hey,

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

    Code:
    typedef enum_AType
    {
       ATypeA,
       ATypeB,
       ATypeC
    } AType;
    
    In the ClassA header I have a method prototype:

    Code:
    -( 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
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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.
     
  3. RossOliver thread starter macrumors regular

    Joined:
    Nov 6, 2006
    #3
    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:

    Code:
    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?
     

Share This Page