Remove println() for release version iOS Swift

前端 未结 19 1512
被撕碎了的回忆
被撕碎了的回忆 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:45

    Varun Naharia has the better solution so far. I would combine his answer with Rivera's ...

    1. create a -D DEBUG flag on the compiler directives, build settings.
    2. then add this code:

      #if !DEBUG
       public func print(_ items: Any..., separator: String = " ", terminator: String = "\n") {
      }
      #endif
      

    This code will convert every print into nothing for release.

提交回复
热议问题