How to determine if Swift has been compiled with Optimization

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

Thanks!

+8
xcode swift
source share
2 answers

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

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

This assumes that you cannot compile without optimization in the Release configuration :-)

If you want to verify that in Swift you need to define the assembly configuration by adding -D DEBUG to the "Other quick flags" to debug the configuration only in the assembly settings. Then you can check this configuration if #if :

 #if DEBUG println("I'm in debug mode!") #endif 
+10
source share

You can use Xcode schemes to add a flag as an argument or environment variables - you can check it with NSProcessInfo - either -arguments or -environment .

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

0
source share

All Articles