判断xcode目前是否处于Debug状态

有时候我们设置宏定义时

#ifdef DEBUG
   //do sth1.
#else 
  //do sth2.
#endif

但是却发现只走sth2,这是因为你没有设置DEBUG,一般Apple已经为我们设置好了 DEBUG 的宏定义,所以,我们可以直接用,但有时候没有设置,你就要知道如何设置,设置步骤也很简单,如下:
点击 Build Settings ,然后在搜索框里输入‘macros’,如图:

屏幕快照 2017-07-06 下午8.05.09.png

如果已经设置过,在 Preprocessor Macros 的 Debug 后面会有 DEBUG=1,如果没有,就手动设置下。
常见的应用场景:

  1. //put this in prefix.pch

    ifndef DEBUG

    undef NSLog

    define NSLog(args, ...)

    endif

  2. ifdef DEBUG

    define NSLogDebug(format, ...) \

    NSLog(@"<%s:%d> %s, " format,
    strrchr("/" FILE, '/') + 1, LINE, PRETTY_FUNCTION, ## VA_ARGS)

    else

    define NSLogDebug(format, ...)

    endif

3.swift

#if DEBUG
  println("I'm running in DEBUG mode")
#else
  println("I'm running in a non-DEBUG mode")
#endif

Additionally you will need to set the DEBUG symbol in Swift Compiler - Custom Flags section for the Other Swift Flags key via a -D DEBUG entry. See the following screenshot for an example:
swift设置的地方稍有不同:

rLan3.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容