iosobjective-cxcode

Is it important not to have unused class imports in Objective - C?


I want to #import my custom class in "ProjectName"-Prefix.pch file in Xcode project.

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import "CustomClass.h"
#endif

But, I won't use my custom class in every project file, so I want to know, will it somehow hurt to my app performance or something else?

Is there any problem with that?
Is it not recommended?


Solution

  • #import ensures that a given header file is only ever actually included once, so there'll be performance issue. From Apple's documentation:

    When you want to include header files in your source code, you typically use a #import directive. This is like #include, except that it makes sure that the same file is never included more than once. The Objective-C samples and documentation all prefer the use of #import, and your own code should too.

    From Learning Objective C: A Primer