chipbk10 chipbk10 - 1 year ago 169
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download