__OBJC__ in objective C

后端 未结 3 1722
悲&欢浪女
悲&欢浪女 2021-02-01 04:53

What does __OBJC__ mean in Objective C?

#import 

#ifdef __OBJC__
    #import 
    #import <         


        
3条回答
  •  逝去的感伤
    2021-02-01 05:24

    This looks like your precompiled header file.

    The precompiled header is shared between all C-dialect files in your project. It's as if all your .c, .cpp, .m and .mm files have an invisible #include directive as the first line. But the Cocoa header files are pure Objective C - trying to include them in a C/C++ source will yield nothing but syntax errors aplenty. Thus the #ifdef.

    If your project only contains Objective C files (.m/.mm), which is the typical case, the #ifdef is not really necessary. But Xcode, which generated this header in the first place, protects you all the same.

    Even if it's not a PCH file, this #ifdef only makes sense if the file is to be included from both Objective C and plain C/C++. But it does not hurt regardless.

提交回复
热议问题