Automatically increment your projects in Xcode
April 26, 2012 Leave a comment
For quite a while, I’ve been trying to figure out how to get my project to automatically increment every time I build and also tie them to our SVN repository. I’ve been using for most of my projects now and thought I’d share it. If you are looking for a quick example, I have a project that uses this on github: https://github.com/brcimo/ScoreTracker
Follow these steps for projects you’ve created:
1. In Build Phases add a script, click on add build phase and choose add run script.
2. Copy and paste the following script in the new script:
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${PROJECT_DIR}/$INFOPLIST_FILE)
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" ${PROJECT_DIR}/$INFOPLIST_FILE
REV=`/opt/subversion/bin/svnversion -nc ${PROJECT_DIR} | /usr/bin/sed -e 's/^[^:]*://;s/[A-Za-z]//'`
echo "BUILD_NUMBER = $REV" > ${PROJECT_DIR}/buildnumber.xcconfig
APPVERSION="`/usr/libexec/PlistBuddy -c \"Print :CFBundleVersion\" \"$CODESIGNING_FOLDER_PATH/Info.plist\"`"
SETTINGSBUNDLEPATH="$CODESIGNING_FOLDER_PATH/Settings.bundle/Root.plist"
/usr/libexec/PlistBuddy -c "Set
referenceSpecifiers:0:Title My App Title - build:'$APPVERSION' revision:'$REV'" "$SETTINGSBUNDLEPATH"
3. Make sure you have SVN installed, if you don’t, check out this post: http://www.richards-blog.com/html/?p=368
Alternatively, you can take out the SVN revision, just delete the part relating to $SETTINGSBUNDLEPATH.
4. Add a Setting Bundle to your app if you don’t already have one, and name it Settings.bundle(that’s the default name).
5. The script above will write the latest value for CFBundleVersion and the last SVN build number in your apps Settings Bundle.
6. In the project summary page, change Build to “0″, no decimals.
7. Run it – Magic!

