Reputation: 126357
For an iPhone app, should I #include or #import , and why?
I've seen it done both ways, e.g., #import & #include.
Upvotes: 5
Views: 7012
Reputation: 400284
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.
Upvotes: 10
Reputation: 12421
Always use #import
- it will make sure that the same header file is never #include
'd twice.
Upvotes: 5
Reputation: 3154
use #import. the advantage is that it does not "re-include" files if they've already been included.
Upvotes: 6