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

Xcode

Xcode Problem Overview


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.

Xcode Solutions


Solution 1 - Xcode

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

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

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

Solution 2 - Xcode

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:

enter image description here



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

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

enter image description here



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

enter image description here



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

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
}

Solution 3 - Xcode

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

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.

Solution 4 - Xcode

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.

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRahul IyerView Question on Stackoverflow
Solution 1 - XcodegeowarView Answer on Stackoverflow
Solution 2 - XcodeKlemenView Answer on Stackoverflow
Solution 3 - XcodejosemigallasView Answer on Stackoverflow
Solution 4 - XcodePat NiemeyerView Answer on Stackoverflow