xcode 为什么没有设置 Swift 编译器标志?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30791661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why isn't Swift compiler flag being set?
提问by Ben Thomas
I want some code to only be executed in a release build, but the code does not get executed when the scheme is configured to use the release configuration.
我希望某些代码仅在发布版本中执行,但是当方案配置为使用发布配置时,代码不会被执行。
What am I missing?
我错过了什么?
I have the following in my app delegate's didFinishLaunchingWithOptions
method:
我的应用程序委托的didFinishLaunchingWithOptions
方法中有以下内容:
#if RELEASE
Countly.sharedInstance().startOnCloudWithAppKey(appKey)
Crittercism.enableWithAppID(appID)
NSLog("crash logging enabled")
#endif
The target build settings look like this:
目标构建设置如下所示:
And the scheme is configured to use the Release configuration when I run the app:
并且该方案配置为在我运行应用程序时使用 Release 配置:
采纳答案by Shripada
You will need to set the preprocessor flags explicitly in the "Swift Compiler - Custom Flags" section, "Other Swift Flags" line.
您需要在“Swift Compiler - Custom Flags”部分的“Other Swift Flags”行中明确设置预处理器标志。
Please check-
请检查-
回答by user157005
It looks like the Swift compiler ignores -D flags that assign a specific value. If you use -DDEBUG and -DRELEASE, it seems to work.
看起来 Swift 编译器忽略了分配特定值的 -D 标志。如果您使用 -DDEBUG 和 -DRELEASE,它似乎可以工作。
回答by Devesh
now you need to set
现在你需要设置
Active Compilation Conditions
under Swift Compiler - Custom Flags
在 Swift 编译器下 - 自定义标志
e.g.
例如
Active Compilation Conditions DEV
主动编译条件 DEV
you can check
你可以检查
#if DEV
print("DEV mode")
#else
print("PROD")
#endif