'__OBJC__ in Objective-C
What does __OBJC__ mean in Objective-C?
#import <Availability.h>
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
Solution 1:[1]
It means the objective C compiler is being used. So you can create hybrid header files that can be used when compiling objective C or C or C++.
You could use it in a header file like this, if you wanted to publish a header file that defined an objective c object that you wanted to make available to c and c++ programmers/code :
#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
Solution 2:[2]
Its just a macro symbol. In this case if that symbol is defined then your program should import the Apple Cocoa frameworks (Foundation and AppKit).
This woudl be the case if you were developing an objective-c / cocoa application. In other words, if you were developing a C++ / carbon application, the __OBJC__ symbol would not be defined and those objective-c dependant frameworks would not be imported.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pup |
| Solution 2 | aldo |
