#ifdef replacement in the Swift language

前端 未结 17 1887
名媛妹妹
名媛妹妹 2020-11-22 10:35

In C/C++/Objective C you can define a macro using compiler preprocessors. Moreover, you can include/exclude some parts of code using compiler preprocessors.

         


        
17条回答
  •  天涯浪人
    2020-11-22 11:41

    Xcode 8 and above

    Use Active Compilation Conditions setting in Build settings / Swift compiler - Custom flags.

    • This is the new build setting for passing conditional compilation flags to the Swift compiler.
    • Simple add flags like this: ALPHA, BETA etc.

    Then check it with compilation conditions like this:

    #if ALPHA
        //
    #elseif BETA
        //
    #else
        //
    #endif
    

    Tip: You can also use #if !ALPHA etc.

提交回复
热议问题