Objective c __目标C中的对象

Objective c __目标C中的对象,objective-c,Objective C,在目标C中,\uuuuuujc\uuuuu是什么意思 #import <Availability.h> #ifdef __OBJC__ #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #endif #导入 #ifdef__OBJC__ #进口 #进口 #恩迪夫 它只是一个宏符号。在这种情况下,如果定义了该符号,那么您的程序应该导入Apple Cocoa框架(Foundati

在目标C中,
\uuuuuujc\uuuuu
是什么意思

#import <Availability.h>

#ifdef __OBJC__
    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
#endif
#导入
#ifdef__OBJC__
#进口
#进口
#恩迪夫

它只是一个宏符号。在这种情况下,如果定义了该符号,那么您的程序应该导入Apple Cocoa框架(Foundation和AppKit)


如果您正在开发objective-c/cocoa应用程序,就会出现这种情况。换句话说,如果你正在开发一个C++/碳应用程序,那么就不能定义O.Objcx符号,而那些不依赖于对象的C框架。

< P>这意味着正在使用目标C编译器。因此,您可以创建混合头文件,可以在编译目标C或C或C++时使用。 <>你可以在一个头文件中使用它,如果你想发布一个头文件,它定义了一个目标C对象,你想让C和C++程序员/代码:

#ifndef MYHEADER_H
#define MYHEADER_H

#ifdef __OBJC__
// Put objective C things in this block
// This is an objc object implemented in a .m or .mm file
@implementation some_objc_object {
}
@end
#endif

#ifdef __cplusplus
#define CLINKAGE "C"
// c++ things that .m or .c files wont understand go in here
// This class, in a .mm file, would be able to call the obj-c objects methods
// but present a c++ interface that could be called from c++ code in .cc or .cpp 
// files
class SomeClassThatWrapsAnObjCObject
{
  id idTheObject;
public:
  // ...
};
#endif
// and here you can declare c functions and structs
// this function could be used from a .c file to call to a .m file and do something
// with the object identified by id obj
extern CLINKAGE somefunction(id obj, ...); 
#endif // MYHEADER_H

这看起来像是预编译的头文件

预编译头在项目中的所有C语言文件之间共享。就好像所有的.c、.cpp、.m和.mm文件都有一个不可见的#include指令作为第一行。但是Cocoa头文件是纯目标C语言——试图将它们包含在C/C++源代码中只会产生大量语法错误。因此#ifdef

如果您的项目只包含目标C文件(.m/.mm),这是典型的情况,那么实际上不需要使用#ifdef。但是,首先生成这个头的Xcode仍然保护您

即使它不是PCH文件,但只有当文件同时包含在Objective C和普通C/C++中时,此ifdef才有意义。但不管怎样,它都不会痛