#ifdef replacement in the Swift language

前端 未结 17 1726
名媛妹妹
名媛妹妹 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:28

    Moignans answer here works fine. Here is another peace of info in case it helps,

    #if DEBUG
        let a = 2
    #else
        let a = 3
    #endif
    

    You can negate the macros like below,

    #if !RELEASE
        let a = 2
    #else
        let a = 3
    #endif
    

提交回复
热议问题