Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xcode

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.

like image 521
Rahul Iyer Avatar asked Feb 20 '14 03:02

Rahul Iyer


People also ask

How do I switch to debug in Xcode?

When you run an application in Xcode, the debugger is automatically started and attached to the process of the application. Click the Run button in the top left or press Command + R. From the moment the application is up and running, we can start inspecting the process and, if necessary, debug it.

How do I make Xcode project in release mode?

Create an Xcode Archive. To test the exact conditions your app user's experience, create a release build. In your Xcode project's scheme editor, set the run destination to a device and adjust the archive task to the Release configuration. Then, choose the Archive option in Xcode's Product menu.


4 Answers

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)

like image 158
geowar Avatar answered Oct 05 '22 04:10

geowar


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
}
like image 45
Klemen Avatar answered Oct 05 '22 06:10

Klemen


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.

like image 37
josemigallas Avatar answered Oct 05 '22 04:10

josemigallas


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.

like image 38
Pat Niemeyer Avatar answered Oct 05 '22 06:10

Pat Niemeyer