# Auto-increment versioning in XCode 5

Ok, this will be quick. There is no built-in feature or that supports automatic code versioning in XCode. I am talking about auto incrementing versions or build numbers in XCode plist, aka “CFBundleVersion” info.plist entry. Here’s a quick one for XCode 5.

Make sure your target has an *Info.plist file. Add an entry there, as number:

Select project root:

Select project root

Expand the Run Script entry and add below code in the text container:

#!/bin/bash
buildPlist=${INFOPLIST_FILE} CFBundleVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $buildPlist) BuildNumber=$(/usr/libexec/PlistBuddy -c "Print BuildNumber" $buildPlist) BuildNumberINCR=$((BuildNumber + 1))
CFBundleVersionINCR=1.0.$((BuildNumberINCR)) /usr/libexec/PlistBuddy -c "Set :BuildNumber$BuildNumberINCR" $buildPlist /usr/libexec/PlistBuddy -c "Set :CFBundleVersion$CFBundleVersionINCR" $buildPlist /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString$CFBundleVersionINCR" $buildPlist  For each build, the BuildNumber will be incremented and both Bundle Version and Bundle Version Short Serial will be updated with your new build number. You might get cool and adopt fancy numbering schemes like 1.0.0b345 replacing: CFBundleVersionINCR=1.0.$((BuildNumberINCR))


With:

CFBundleVersionINCR=$((majorVersion)).$((minorVersion)).$((revisionVersion))b$((BuildNumberINCR))


Now, imagination is the limit.

Enjoy.

AP

Filed in Apple Programming, How To's and tagged , . Bookmark the permalink.

### 2 Comments to Auto-increment versioning in XCode 5

1. Kevin Becker says:

This doesn’t seem to work for me. The error indicates that it doesn’t like the spaces in the plist file name. Can the script be modified to allow spaces?

• AP says:

Hi, Kevin,
Thank you for your comment. Sorry for getting back to you with such a delay.
The script should work. With or without spaces. Can you post it here to see what is the problem ?
Regards,
AP