Last Updated: July 04, 2023
·
5.114K
· _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.

#!/bin/bash
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.

Enjoy!

2 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 ·

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 ·