Bert B.
Bert B.

Reputation: 579

Defining Global Constants in Objective-C

I have a constants.h file that looks something like

#ifndef constants_h
#define constants_h

#define MyAdUnitID @"XXXXXXX"
#define GoogleAnalyticsID = @"XXXXX"

#endif

and want to reference it throughout my other implementation files. These are just simple string values that I want as NSString instances throughout my program, but can't seem to get it to work.

If there is a better practice to this, please let me know!

Upvotes: 2

Views: 2253

Answers (1)

fannheyward
fannheyward

Reputation: 19277

Use extern instead of define.

in .h:

extern NSString* SHKFacebookAppID;

in .m:

NSString* SHKFacebookAppID = @"1234567890";

Upvotes: 7

Related Questions