Search code examples
iosobjective-cuicolor

What does @class mean in objc files


I have noticed that when going through a lot of the framework public header files, there are things like : ex :

@class UIImage;

NS_CLASS_AVAILABLE_IOS(2_0) @interface UIColor : NSObject <NSSecureCoding, NSCopying> {
    @private
}

I understand the NS_CLASS_AVAILABLE_IOS(2_0) and the rest, but I don't understand the use of the @class keyword.

If someone could explain the use, and how it is used I would appreciate it very much!


Solution

  • This is a forward declaration: it basically tells the compiler that the class UIImage exists, without specifying what exactly it looks like.

    It is recommended to use forward declaration of classes instead of importing header in header files to avoid coupling of classes and improve compilation time.