Automatic build versions from git in Xcode (and other goodies)
Installation procedure for pre-build actions to automatically populate Xcode Info.plist with dynamic data.
1. Xcode Scheme pre-action
Edit Xcode Scheme and add a pre-action script.
Copy the contents of
preaction.sh into the pre-action script box.
2. Copy processing file
- Modify it's variables or path to
3. Edit Xcode Build Settings
- For the
Project Build Settingsadd a new User-Defined variables called
ENVIRONMENT, for each scheme set the appropriate name eg
- For each Target Build Settings set
Preprocess Info.plist fileto YES.
environment_preprocess.h(or the output file if you renamed it
Info.plist Preprocessor Prefix File
4. Install plist file
development.plist file to
config/environments/development.plist. DO NOT include this file in any Target Memberships.
If you have several schemes setup in the previous step (
ENVIORMENT) you need to copy this file to each option if you use multiple build schemes and
5. Setup environment variables
development.plist (and others) is used to populate data in the
Modify contents as needed and don't forget to also modify the
This is really where the magic happens. The rest is just for running this script and processing the output.
TIP 1: You can run pretty much anything in the
environment_preprocess.h script if you want to setup link to a local development server you can use the
hostname command to get your current build computer's network name.
TIP 2: You can use it to use git commit count as the build version/number.
(Both of these are included in the script already.)
6. Using environment variables
- Use those generated environment variables in your
7. Run Build!
This will generate the
environment_preprocess.h file and make it available for inclusion in your
It's advisable to exclude the generated file from any version control system.