9

As some of you may be aware when running in fully Debug-Mode swift can be terribly slow. Is there a way i can print out a message in code or to the GUI to let me know if I somehow forgot to compile it correctly. I'm running in mixed mode so if somebody can give me Objc and Swift code that would be super awesome.

Thanks!

Jeef
  • 26,861
  • 21
  • 78
  • 156

2 Answers2

11

I don't think you can detect this at runtime, but you can use the DEBUG preprocessor macro (in Objective-C) that is defined in the Debug configuration by default:

#ifdef DEBUG
NSLog(@"I'm in debug mode!");
#endif

This assumes that you don't compile without optimizations in the Release configuration :-)

If you want to check that in Swift, you need to define a Build Configuration by adding -D DEBUG to "Other Swift Flags" for the Debug configuration only in the Build settings. Then you can check for that configuration if #if:

#if DEBUG
println("I'm in debug mode!")
#endif
jou
  • 5,824
  • 3
  • 22
  • 24
  • So now way at runtime to figure out what level of optimization was used? – Jeef Sep 18 '14 at 16:38
  • 1
    @jeef use this technique to set a flag, and then you can check the flag at runtime – Chris K Sep 18 '14 at 16:40
  • If somebody wonders why these flags aren't working make sure Xcode shows them in the order @jou specified them here -D DEBUG. If Xcode shows DEBUG -D it won't work. – zumzum Mar 21 '16 at 11:02
0

You can use Xcode's schemes to add a flag as an argument or in the environment variables - you can then check for it using NSProcessInfo - either -arguments or -environment.

In Xcode, go to Product > Scheme > Edit Scheme in the menu bar, select Run and under the Arguments tab, add either the argument or environment variable.

Charlie Monroe
  • 1,210
  • 9
  • 24