Skip to content

iOS Debug mode Logs

Platform License

Objective C:

Place this code in your .pch file:

#ifndef NSLog
#ifdef DEBUG
#define NSLog(_format_, ...) NSLog(_format_, ## __VA_ARGS__)
#else
#define NSLog(_format_, ...)
#endif
#endif

Now you can use NSLog for all log messages that should only be printed in your debug builds.

Swift 2.2:

func print(items: Any..., separator: String = " ", terminator: String = "\n") {
  #if DEBUG
    Swift.print(items[0], separator:separator, terminator: terminator)
  #endif
}

Swift 3.0:

func print(_ item: @autoclosure () -> Any, separator: String = " ", terminator: String = "\n"){
  #if DEBUG
    Swift.print(item(), separator:separator, terminator: terminator)
  #endif
}

This executes just in the case where you are printing just one thing, which is usually call in DEBUG mode. That's because item() is not called in Release mode.

Let's grow together 🌱

Cheers 🍻