Remove println() for release version iOS Swift

前端 未结 19 1525
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 15:55

I would like to globally ignore all println() calls in my Swift code if I am not in a Debug build. I can\'t find any robust step by step instructions for this a

19条回答
  •  忘掉有多难
    2020-11-29 16:53

    XCode 8 introduced a few new build settings.
    In particular one referred to Active Compilation Conditions does in a similar way what Other Flags settings did.

    "Active Compilation Conditions" is a new build setting for passing conditional compilation flags to the Swift compiler.

    As per XCode 8 (tested in 8.3.2) you will get this by default:

    So without any config you can write the following:

    #if DEBUG
        print("⚠️ Something weird happened")
    #endif
    

    I strongly recommend you that if you use this approach extensively create a class/struct/function that wraps this logging logic. You may want to extend this further down the road.

提交回复
热议问题