7

Possible Duplicate:
@class vs. #import

In Objective-C, what are the best practices for using forward declarations (of classes or protocols) vs. #import-ing files? And why are forward declarations recommended at all if #import ensures no file is included more than once? I'm thinking of iOS app development in particular, but I assume this applies to Objective-C in general.

Community
  • 1
  • 1
jrdioko
  • 32,230
  • 28
  • 81
  • 120

1 Answers1

16

My rule of thumb is: If a forward declaration is sufficient, I use it. Otherwise I import the full declaration with #import.

This is mainly from my experience with large projects where the careless use of #import (or #include) can easily lead to situation where the compiler has to compile more than a million lines of code for each non-header file and where minor changes in a single header file trigger tons of recompilation. As a consequence, compile the code takes a long time.

Codo
  • 75,595
  • 17
  • 168
  • 206