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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With