I have an Xcode project, which has multiple targets. I want to define a variable somewhere (a variable for build number, to be precise) where I can reference as the Bundle version
in the Info.plist of each project without updating them individually. e.g. I'll set bundle version to $(BUILD_NUMBER)
once (I've made up the name) for each target then I'll increment that BUILD_NUMBER
variable on each release. Is this possible? If yes, how? I've seen Adding a build configuration in Xcode and How to create variables for use in Xcode build settings values? but the settings are greyed out:
Asked
Active
Viewed 910 times
1

Community
- 1
- 1

Can Poyrazoğlu
- 33,241
- 48
- 191
- 389
-
First, you need to go to "Build Settings" and select a configuration (possibly Debug or Release). Then "Add Conditional Setting" or "Add User-Defined Setting" will be enabled. This [link](https://developer.apple.com/library/ios/recipes/xcode_help-project_editor/Articles/Adding%20a%20Conditional%20Build%20Setting.html) partially illustrates how it is done. Second, it might be pain in the ass to manually increment build number as other developers step in and start working at the same project. You might want to consider using some CI solutions like `fastlane` instead. – Ozgur Vatansever Sep 12 '16 at 07:30
-
@ozgur it worked perfectly. could you please post it as an answer so that I can accept it? – Can Poyrazoğlu Sep 12 '16 at 07:34
-
Frankly, my answer doesn't cover your actual question about how to alter a user-defined variable programmatically thus, I'd rather leave my answer as is. But, glad to hear it worked for you. – Ozgur Vatansever Sep 12 '16 at 08:14
-
@ozgur actually my question was mainly about being able to declare a common variable, auto incrementing would be nice but isn't mandatory. – Can Poyrazoğlu Sep 12 '16 at 08:15
-
@ozgur and using a CI solution solely for build number increment would be a bit overkill in my case :) but that's okay – Can Poyrazoğlu Sep 12 '16 at 08:17
1 Answers
2
First, you need to go to Build Settings
and select a configuration (possibly Debug or Release). Then Add Conditional Setting or Add User-Defined Setting options will be enabled. This link illustrates how it is done.
Second, it might be error-prone to manually increment build number especially after some other developers step in and start working on the same project. You might want to consider using some CI solutions like fastlane instead. It makes use of agvtool
for app versioning so you might want to also look at that as well.

Ozgur Vatansever
- 49,246
- 17
- 84
- 119
-
it works perfectly. just a quick addition: I didn't select a configuration such as debug or release, I've just went to the build settings of the projects and followed the steps. it applies to both debug and release (or any other configuration), which is what I need anyway. – Can Poyrazoğlu Sep 12 '16 at 09:49