AppCode 2023.1 Help

Environment variables and program arguments

You can influence the runtime behavior of your app by adding program arguments and environment variables to run/debug configurations.

Add program arguments

  1. From the main menu, select Run | Edit Configurations or choose Edit Configurations from the run/debug configurations selector on the toolbar.

  2. In the Run/Debug Configurations dialog that opens, select a configuration where you want to pass the arguments.

  3. Type the arguments in the Program arguments field. The arguments should be separated with spaces.

    Program arguments

    Click the Expand field icon to expand the text field, so you can view and edit the whole list of arguments.

    Click the Add button to insert a macro from the list. A macro is a sequence of computing instruction available as a single program statement. You can use macros, for example, for inserting the current file name, path, encoding, and so on:

    List of macros

You can access the list of program arguments using the CommandLine enumeration:

for arg in CommandLine.arguments { print("\(arg)") }

Add environment variables

  1. From the main menu, select Run | Edit Configurations or choose Edit Configurations from the run/debug configurations selector on the toolbar.

  2. In the Run/Debug Configurations dialog, select a configuration you want to add the environment variables to.

  3. Type the variable name and value: <name>=<value>. If you add several variables, they should be separated with semicolons ;.

    Alternatively, click the Environment
variables icon and add the variable name and value to the User environment variables list.

    Environment variables

    In the dialog that opens, you can also see the list of available system environment variables. Clear the System environment variables checkbox if you don't want to use the system environment variables for the selected run/debug configuration.

You can read environment variables using the environment property of the ProcessInfo object:

if ProcessInfo.processInfo.environment["VERBOSITY_LEVEL"] == "DEBUG" { //... }

Last modified: 17 March 2022