chipbk10 chipbk10 - 10 months ago 104
Objective-C Question

#define a global preprocessor directive in a separate file in Objective-C

I want to define a global preprocessor directive in my app. For example:

In MyProgram.h, I define:


I import this file from beginning in appDelegate.m.

For the later use, in another file, I refer to this global preprocessor directive.

In MyWebService.h, I define:

static NSString *MY_SERVER = @"";
static NSString *MY_SERVER = @"";

However, the value of
is always @"". How to make it work properly? Thanks.


Define it in .pch. And you will never forget to include .h-file where you have defined USE_LOCALHOST.

Or you can define it in build settings in Preprocessor Macros. For example only for Debug.