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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:16:14  来源:igfitidea点击:

Why isn't Swift compiler flag being set?

xcodeswift

提问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 didFinishLaunchingWithOptionsmethod:

我的应用程序委托的didFinishLaunchingWithOptions方法中有以下内容:

#if RELEASE
    Countly.sharedInstance().startOnCloudWithAppKey(appKey)
    Crittercism.enableWithAppID(appID)
    NSLog("crash logging enabled")
#endif

The target build settings look like this: screenshot of the Swift Compiler - Custom Flags section in Xcode

目标构建设置如下所示: Swift Compiler - Xcode 中的自定义标志部分的屏幕截图

And the scheme is configured to use the Release configuration when I run the app: Screenshot of release scheme configuration in Xcode

并且该方案配置为在我运行应用程序时使用 Release 配置: Xcode中发布方案配置截图

采纳答案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-

请检查-

In absence of preprocessor macros, is there a way to define practical scheme specific flags at project level in Xcode project

在没有预处理器宏的情况下,有没有办法在 Xcode 项目的项目级别定义实用的方案特定标志

回答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