如何仅使用快捷键在调试或发布模式下切换正在运行的 Xcode 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21897728/
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-09 05:04:24  来源:igfitidea点击:

How to toggle running Xcode project in debug or release mode by using only shortcut keys?

xcode

提问by Kaizer Sozay

By default, to "run" my project in release mode, I need to edit the scheme's run settings to use "release" instead of debug.

默认情况下,要在发布模式下“运行”我的项目,我需要编辑方案的运行设置以使用“发布”而不是调试。

To not have to edit the scheme each time I want to switch between debug and release mode, I created a new scheme which runs in release. But this is still tedious since I need to click on the relevant scheme if I want to switch.

为了每次在调试和发布模式之间切换时都不必编辑方案,我创建了一个在发布中运行的新方案。但这仍然很乏味,因为如果我想切换,我需要点击相关的方案。

Is there a way that I can automatically (build + run) in debug / release mode using only short cut keys ?

有没有一种方法可以仅使用快捷键在调试/发布模式下自动(构建 + 运行)?

I don't wan't to profile! Because that launches instruments etc.

我不想配置文件!因为那会发射仪器等。

EDIT: To be clear - I'm always running on the device.

编辑:要清楚 - 我总是在设备上运行。

回答by geowar

Debugging build: "Product" Menu => "Build For" => "Running" (shift-command-R)

调试构建:“产品”菜单 =>“构建为”=>“运行”(shift-command-R)

Release build: "Product" Menu => "Build For" => "Profiling" (shift-command-I)

发布版本:“产品”菜单 =>“构建目的”=>“分析”(shift-command-I)

Run without building (whichever you just built): "Product" menu => "Perform Action" => "Run without building" (control-command-R)

无需构建即可运行(无论您刚刚构建的哪个):“产品”菜单 =>“执行操作”=>“无需构建即可运行”(control-command-R)

回答by Klemen

There is one way that I use it for my projects.

有一种方法可以将它用于我的项目。

In Xcode, go to the the project settings (project, not target) and add "beta" configuration to the list:

在 Xcode 中,转到项目设置(项目,而不是目标)并将“beta”配置添加到列表中:

enter image description here

在此处输入图片说明



Then you need to create new scheme that will run project in "beta" configuration. To create scheme go here:



然后你需要创建新的方案,以“beta”配置运行项目。要创建方案去这里:

enter image description here

在此处输入图片说明



Name this scheme whatever you want. The you should edit settings for this scheme. To do this, tap here:



随意命名这个方案。您应该编辑此方案的设置。为此,请点击此处:

enter image description here

在此处输入图片说明



Select Archive tab where you can select Build configuration



选择存档选项卡,您可以在其中选择 Build configuration

enter image description here

在此处输入图片说明





Then you need to add a key Configwith value $(CONFIGURATION)the projects info property list like this:

然后,你需要添加一个键Config与值$(CONFIGURATION)的项目信息属性列表如下:

enter image description here

在此处输入图片说明



Then its just the matter what you need in code to do something specific to beta build:



然后就是你需要在代码中做一些特定于 beta 构建的事情:

let config = Bundle.main.object(forInfoDictionaryKey: "Config") as! String
if config == "Release" {
  // app running in release configuration
}
else if config == "Beta" {
  // app running in beta configuration
}

回答by Pat Niemeyer

In XCode 7 you can switch between schemes using the shortcut: control-command-right/left bracket (select next scheme, select previous scheme). So I think creating two schemes is your best bet.

在 XCode 7 中,您可以使用快捷方式在方案之间切换:控制命令-右/左括号(选择下一个方案,选择上一个方案)。所以我认为创建两个方案是你最好的选择。

BTW, for everyone asking why one would do this - If you are writing a high performance piece of code you will find yourself constantly switching between release and debug mode for a lot of reasons. Release mode (especially in swift with whole module optimization on) takes forever to build and optimization changes stack traces, etc.

顺便说一句,对于每个问为什么要这样做的人 - 如果您正在编写一段高性能代码,您会发现由于很多原因,您会不断在发布和调试模式之间切换。发布模式(尤其是在整个模块优化的 swift 中)需要永远构建和优化更改堆栈跟踪等。

回答by josemigallas

The equivalent in XCode that you seek is the "schemes".

您寻求的 XCode 中的等价物是“方案”。

Right of the play/stop buttons, there a pretty handy scheme selector. You just need to create a scheme for debug and another for distribution. enter image description here

在播放/停止按钮的右侧,有一个非常方便的方案选择器。您只需要创建一个用于调试的方案和另一个用于分发的方案。 在此处输入图片说明

enter image description here

在此处输入图片说明

In order to make a scheme for debug or distribution, simply go to the scheme configuration (either selecting "edit scheme..." or "new scheme...") and choose the correct build configuration under "Run -> Build Configuration": enter image description here

为了制定调试或分发方案,只需转到方案配置(选择“编辑方案...”或“新方案...”)并在“运行->构建配置”下选择正确的构建配置: 在此处输入图片说明

Note: I have XCode 9.1, I don't know if this is valid for older versions.

注意:我有 XCode 9.1,我不知道这对旧版本是否有效。