开发者

Objective-C forward declarations vs. #imports [duplicate]

This question already has answers here: Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜