Last Updated: February 25, 2016
· _jeffreyjackson

Auto-Increment Xcode Build

Here is a quick example on how you can set up a run script in Xcode to auto-increment your build number.

Go to the target in the navigator window, and choose build phase. Add a build phase, and add run script.

Add this simple bash script which reads the info.plist, adds 1 to bundle version in decimal then saves it.

bN=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
bN=$((bN += 1))
bN=$(printf "%d" $bN)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $bN" "$INFOPLIST_FILE"

Modify the script to adhere to your build numbering convention.


3 Responses
Add your response


Clever, but Apple provides a tool expressly for this purpose, agvtool - the Apple-generic versioning tool.

Given that your project as a CFBundleVersion and CFBundleShortVersionString set in the Info.plist for each of your targets, you just need to switch the Versioning System to Apple Generic under the build settings. I recommend setting this at the project level and let your targets inherit it.

From then on you can use agvtool bump to bump the build number by one. Easy, and no mucking around with the PList yourself (though I suspect that agvtool is just basically doing what you suggest under the covers).

over 1 year ago ·

I actually like this alternative to agvtool. The problem with agvtool is that it modifies your .pbxproj file(s). If you're collaborating with other people, it helps to not change your .pbxproj file unless there's actually something that needs changing, because it causes conflicts with every merge. Thanks for sharing!

over 1 year ago ·

Surely it just causes the conflict in the Info.plist file rather than your .xcodeproj. The problem hasn't really changed.

over 1 year ago ·