For an iPhone app, should I #include or #import , and why?
I've seen it done both ways, e.g., #import & #include.
If the header file has traditional include guards, it really doesn't matter which you use, it's more of a stylistic choice. There might be a tiny performance boost if you use #import
instead of #include
, but I doubt it will be noticeable, since most compilers these days are smart enough to recognize include guards and optimize accordingly.
If, on the other hand, the header file does not have include guards, then you should always use #import
, since #import
will ensure that the header will only get included once -- if you accidentally #include
such a header twice, you will almost certainly get a deluge of compiler errors about redefinitions etc.
Since most Objective-C headers (especially those coming from the Objective-C runtime or the Cocoa headers) do not have include guards, you should use #import
when including those. When including standard C library headers or headers from a third-party library, it doesn't matter which you choose -- pick one style and be consistent.
use #import. the advantage is that it does not "re-include" files if they've already been included.
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