65

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.

Rahul Iyer
  • 19,924
  • 21
  • 96
  • 190
  • 1
    I need a way to switch between debug and release mode quickly, ideally using only shortcut keys. – Rahul Iyer Feb 20 '14 at 03:58
  • 1
    This bothers me so much. I really like Visual Studio's drop down for selecting the build configuration you want to use. My problem with Xcode would be solved if I could change the default build configuration for "Run" to "Release." – chrisdembia Mar 09 '16 at 20:25

4 Answers4

42

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)

geowar
  • 4,397
  • 1
  • 28
  • 24
  • 1
    That doesn't achieve my objective. Suppose I just finish running and installing the binary on my iOS device using shift+cmd+r. Then doing shift+cmd+i , followed by ctrl+cmd+r, doesn't replace the debug build on my device with the release build. Did I misunderstand your answer ? – Rahul Iyer Feb 22 '14 at 02:21
  • 1
    No; you never mentioned anything about "installing the binary on my iOS device". I answered the question you asked (about Xcode). – geowar Mar 10 '14 at 16:24
  • Using "Build for Profiling" followed by "Run without building" runs in Debug mode (not whichever one you built). – Paula Vasconcelos Gueiros Mar 04 '22 at 20:22
20

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.

josemigallas
  • 3,761
  • 1
  • 29
  • 68
17

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
}
Klemen
  • 2,144
  • 2
  • 23
  • 31
7

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.

Pat Niemeyer
  • 5,930
  • 1
  • 31
  • 35