Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 development in particular, but I assume this applies to Objective-C in general.

like image 450
jrdioko Avatar asked May 20 '11 18:05

jrdioko


Video Answer


1 Answers

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.

like image 163
Codo Avatar answered Nov 03 '22 01:11

Codo