__OBJC__
在Objective C中的含义是什么?__OBJC__ in objective C
24
A
回答
28
这看起来像你的预编译头文件。
预编译头文件在项目中的所有C语言文件之间共享。就好像所有的.c,.cpp,.m和.mm文件都有一个不可见的#include指令作为第一行。但Cocoa头文件是纯粹的Objective C--试图将它们包含在C/C++源代码中,除了语法错误之外,它们只会产生任何东西。因此#ifdef。
如果您的项目只包含Objective C文件(.m/.mm),这是典型情况,那么#ifdef并不是真的必要。但是,首先生成这个头文件的Xcode,也可以保护你。
即使它不是PCH文件,只有从Objective C和普通C/C++中包含该文件,该#ifdef才有意义。但不管怎样都不会伤害。
1
它只是一个宏观符号。在这种情况下,如果定义了该符号,那么程序应该导入Apple Cocoa框架(Foundation和AppKit)。
如果你正在开发一个Objective-C/cocoa应用程序,这种情况就是这种情况。换句话说,如果您正在开发C++/Carbon应用程序,那么将不会定义符号,并且这些不依赖于Objective-C的框架将不会被导入。
33
这意味着目标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
相关问题
- 1. __OBJC__相当于Objective-C++
- 2. array in objective c
- 3. @synthesize in Objective-c?
- 4. ARC in Objective-C
- 5. BDD in Objective-C
- 6. @“%@ in Objective C?
- 7. UIGestureRecognizer in objective-C++
- 8. KeyListener in Objective-c
- 9. import in objective C
- 10. JSON in objective-c
- 11. NOT(!)in objective c
- 12. @synchronized in Objective-C
- 13. CGRectMake in Objective-C
- 14. methods in objective-c
- 15. #defines in objective-c
- 16. memoryWarning in Objective-c
- 17. singleton in objective c
- 18. self in objective-c
- 19. hide @property in objective C
- 20. 符号“|” in Objective C
- 21. AbstractFactory pattern in objective-c
- 22. Javascript promise in objective-c
- 23. usleep()in objective c code
- 24. RTSP Streaming in objective C
- 25. Assertion Failed in Objective C
- 26. singleton class in objective-C
- 27. Crop ObjectiveConcept in Objective C
- 28. (void)^(void)in objective-c?
- 29. 滑动导航in objective-c
- 30. 返回1 in objective-c