什么是__OBJC__
在 Objective-C 中是什么意思?
#import <Availability.h>
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
这意味着正在使用目标 C 编译器。因此,您可以创建可在编译 Objective 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)