57

XCode has a number of built-in variables that are used for convenience in Build Settings, for example "$(PRODUCT_NAME)" or "$(CURRENT_ARCH)".

Can I define my own variables? How / where?

Ben Flynn
  • 18,524
  • 20
  • 97
  • 142

4 Answers4

123

In XCode 5 this has changed slightly.

  1. Select the project or target in the left side of the editor
  2. Go to the Editor menu in the top menu bar
  3. Select "Add Build Setting" and then "Add User-Defined Build Setting"

enter image description here

Jon Deokule
  • 1,506
  • 2
  • 12
  • 7
  • 1
    is there any way to add a user defined build settings which can select a value from set of predefined values – Johnykutty Jul 01 '14 at 08:55
  • 5
    When the selections are grayed out (like in the image above), you need to select the Project from the "Project and Target" list, then click the "Build Settings" tab, as specified in this SO question and answer: http://stackoverflow.com/questions/19842746/adding-a-build-configuration-in-xcode – Jeremy Mullin Jul 16 '14 at 14:53
  • @Johnykutty this may be useful http://blog.xebia.com/2015/01/30/run-your-ios-app-without-overwriting-the-app-store-version/ – James Kuang May 21 '15 at 17:04
  • Can this be considered a kind of Obfuscation? – Kunal Gupta May 24 '18 at 07:04
17

It's at the top of the build settings panel in Xcode 10.

enter image description here

Yousef Hamza
  • 347
  • 1
  • 3
  • 13
13

Create a user-defined build setting. To create one in Xcode 4 select your project from the project navigator to open the project editor. Select your project or target from the left side of the editor. Click the Build Settings button at the top of the editor. Click the Add Build Setting button at the bottom of the editor and choose Add User-Defined Setting.

Swift Dev Journal
  • 19,282
  • 4
  • 56
  • 66
7

User-defined setting can be added in Xcode as specified below:

Xcode 4.x :

Select PROJECT / TARGETS -> “Add Build Setting” (option present in bottom-right corner of Xcode) -> “Add User-Defined Setting”

enter image description here

Xcode 5.x :

Select PROJECT / TARGETS -> Editor menu -> “Add Build Setting“ -> “Add User-Defined Setting”

enter image description here

This will add User-defined setting. Enter key-value for setting.

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
  • is there any way to add a user defined build settings which can select a value from set of predefined values – Johnykutty Jul 01 '14 at 08:55
  • 1
    yes, there is a way to define values to preprocessor variables in build settings, which can be accessed from code. Goto `"Apple LLVM - Preprocessing"` section in `Build Settings` of your project and you can add variables like `LOGGING=1` and which can be accessed from code as `#if LOGGING`. – Trident Jul 14 '15 at 16:19
  • It seems that on Xcode 12.5, the Editor menu doesn't work, but the top-right add button next to search bar does now. – Neal.Marlin May 29 '21 at 11:01