Reputation: 10129
I have a general coding style question for Objective C.
When I have a #define in a file, I put it directly below the #import lines of code and above the @implementation line of code:
#import "MyLibrary.h"
#define myConstant 99
@implementation MyClass
Is this standard style, or is there a standard style of a place to put the defines?
Upvotes: 3
Views: 549
Reputation: 3658
You should always put your #define
s after any imports. Otherwise you will pollute the imported files with your #define
values and in extreme cases change how they work.
Upvotes: 9
Reputation: 49414
I've never seen any standard on this. #define
s are almost always at the top of the file (after #import
s), but the location doesn't much matter.
Upvotes: 1
Reputation: 4424
Objective-C doesn't really use defines to define constants.
However it is possible to do as you do because Objective-C is backwards compatible with C.
This is how I would do it in Objective-C, in the header file:
extern int const MyConstant;
In the implementation file:
int const MyConstant = 99;
Upvotes: 2