iphone: get User Defined variable in Target's setting by code?

后端 未结 2 1623
萌比男神i
萌比男神i 2021-02-01 02:57

My project have multi-targets. Each target has its own Class file for setting stuff. I want to store that Class name in a target setting (Info.pl

2条回答
  •  长发绾君心
    2021-02-01 03:47

    You can not directly use a variable defined in the build settings. These variables are meant to be used by build tools.

    Instead define a preprocessor macro in the Preprocessor Macros Variable like 'MYVAR=5'. You can access these macros in your code like:

    #if MYVAR==5
        //Do something
    #endif
    

    Please note, that the evaluation of these expressions happens at build-time not at runtime.

    It is very typical use to just define a Macro without caring for the value. For example define 'DEBUG=1' in the debug build settings and 'RELEASE=1' in the release build settings.

    You can then test using #ifdef or #ifndef

    #ifdef DEBUG
        // Log
    #endif
    

提交回复
热议问题