Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify if Swift was compiled with Optimization

Tags:

xcode

swift

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!

like image 371
Jeef Avatar asked Sep 18 '14 15:09

Jeef


1 Answers

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
like image 186
jou Avatar answered Sep 20 '22 22:09

jou