Objective-C forward declarations vs. #imports [duplicate]
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 developmen开发者_高级运维t in particular, but I assume this applies to Objective-C in general.
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.
精彩评论