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.
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.
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.
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)
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
}
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With