How to dynamically set a static #define variable in a header (.h) file?

I use the open source component in my iOS project (sharekit) and they defined static variables in the header file. For example, in SHKConfig.hthey define the Application Name as:

#define SHKMyAppName            @"My App Name"

What I would like to do is make this dynamic; I do not want to hard code these variables in this particular file. Since there is no method in the header file (as far as I know) viewDidLoad, how can I possibly dynamically assign this variable?

Is it possible?

Thank you in advance!

+3
source share
3 answers

#define . , .

. Provider

+ (NSString *)getYourConstant;

#import "Provider.h"

#define kTheConstantYouNeed [Provider getYourConstant]
+3

ifdef, . " ", . MACRO, SHKMyAppName @"My App Name.

. ( XCode) , . #define :

#if defined(PROJECT_APP_01_BUILD)
#define SHKMyAppName @"My App 01"
#elif defined(PROJECT_APP_02_BUILD)
#define SHKMyAppName @"My App 02"
#elif defined(PROJECT_APP_03_BUILD)
#define SHKMyAppName @"My App 03"
#endif

, App 01 SHKMyAppName @"My App 01"'. When you are compiling **App 02**, macro SHKMyAppName will be replaced by @ "My App 02". , .

+1

You can move these definitions to one appinfo.h file and include it in other headers.

It can also be a good place for version information.

eg.

In SHKConfig.h:

#include "MyAppInfo.h"
#define SHKMyAppName    MyAppName // define MyAppName elsewhere

And in MapAppInfo.h:

#define MyAppName "Bla bla"


Or...

In SHKConfig.h:

#define SHKMyAppName    MyAppName // define MyAppName elsewhere

And in the application compiler settings add:

-DMyAppName=\"Bla bla\"
+1
source

All Articles