如何识别 Swift 是否是使用优化编译的 [英] How to identify if Swift was compiled with Optimization

查看:31
本文介绍了如何识别 Swift 是否是使用优化编译的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们中的一些人可能知道,在完全调试模式下运行时,swift 可能会非常慢.有没有办法可以在代码或 GUI 中打印出一条消息,让我知道我是否以某种方式忘记了正确编译它.我在混合模式下运行,所以如果有人能给我 Objc 和 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.

谢谢!

推荐答案

我认为您无法在运行时检测到这一点,但您可以使用 DEBUG 预处理器宏(在 Objective-C 中)默认情况下在调试配置中定义的:

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 :-)

如果你想在 Swift 中检查,你需要定义一个 构建配置,将-D DEBUG添加到Other Swift Flags"仅用于调试配置构建设置.然后您可以检查该配置,如果 #if:

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

这篇关于如何识别 Swift 是否是使用优化编译的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆