How to toggle running Xcode project in debug or release mode by using only shortcut keys?
XcodeXcode 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:
Then you need to create new scheme that will run project in "beta" configuration. To create scheme go here:
Name this scheme whatever you want. The you should edit settings for this scheme. To do this, tap here:
Select Archive tab where you can select Build configuration
Then you need to add a key Config
with value $(CONFIGURATION)
the projects info property list like this:
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.
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":
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.