#include or #import <objc / runtime.h>?

Do I need #include or #import for an iPhone application and why?

I saw this in both directions, for example # import and #include .

+4
source share
3 answers

If the header file has a traditional include guards , it really does not matter what you use, it is rather a stylistic choice. There may be a slight increase in performance if you use #import instead of #include , but I doubt it will be noticeable, since most compilers these days are smart enough to recognize included guards and optimize accordingly.

If, on the other hand, there are no defenders in the header file, then you should always use #import , since #import ensures that the header will only be included once - if you accidentally #include such a header twice, you will almost certainly get a stream compiler errors about overrides, etc.

Since most Objective-C headers (especially those from the Objective-C or Cocoa headers) do not contain defenders, you should use #import when they are included. When you include standard C library libraries or headers from a third-party library, it does not matter which one you choose - choose one style and be consistent.

+10
source

use #import. the advantage is that it does not β€œre-include” files if they have already been included.

+6
source

Always use #import - it will be sure that the same header file will never be #include twice.

+5
source

Source: https://habr.com/ru/post/1398715/


All Articles