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

Select project root

Then go to menu, select Editor → Add Build Phase → Add Run Script Build Phase:

Choose Add Run Script Build PhaseExpand the Run Script entry and add below code in the text container:

Expand run script

CFBundleVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $buildPlist)
BuildNumber=$(/usr/libexec/PlistBuddy -c "Print BuildNumber" $buildPlist)
BuildNumberINCR=$((BuildNumber + 1))
/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=$((majorVersion)). $((minorVersion)).$((revisionVersion))b$((BuildNumberINCR))

Now, imagination is the limit.



Usage of void in C

Going into some USB programming for a project I am into (on my Mac), I ran into this and I thought would be nice and useful to elaborate a bit. This is about void* pointers and callbacks in C. USB device discovery and probing under IOKit makes heavy use of callbacks, I wanted to write […]

Using LLDB Commands in XCode 4

The rationale for Apple’s move to LLVM and slowly parting with the aging GCC has a long history and is out of the scope of this brief tutorial on LLVM commands. The primary reason for switching from GCC to Clang — probably — is the incompatibility of GCC’s GPL v3 license with the goals of […]

2 responses 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 ?

Leave a Reply

Your email address will not be published. Required fields are marked *