Skip to content

Instantly share code, notes, and snippets.

@rodydavis
Last active September 15, 2018 08:34
Show Gist options
  • Save rodydavis/14a408e130a0968a1173ce2eead7ca4d to your computer and use it in GitHub Desktop.
Save rodydavis/14a408e130a0968a1173ce2eead7ca4d to your computer and use it in GitHub Desktop.
Auto Increment Build and Version Numbers
#Works with Xcode 9 (Confirmed)
#1. Go to "Edit Schemes"
#2. Go to "Build"
#3. Go to "Pre-Actions"
#4. Select YOUR app in "Provide Build Settings from:"
#5. Paste Below Script in Box
#6. Build Project
#Build Number ++
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$PRODUCT_SETTINGS_PATH")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$PRODUCT_SETTINGS_PATH"
#Version Number ++
VERSIONNUM=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$PRODUCT_SETTINGS_PATH")
NEWSUBVERSION=`echo $VERSIONNUM | awk -F "." '{print $3}'`
NEWSUBVERSION=$(($NEWSUBVERSION + 1))
NEWVERSIONSTRING=`echo $VERSIONNUM | awk -F "." '{print $1 "." $2 ".'$NEWSUBVERSION'" }'`
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $NEWVERSIONSTRING" "$PRODUCT_SETTINGS_PATH"
@Ariandr
Copy link

Ariandr commented May 17, 2018

Actually, doesn't work for me, Xcode 9.3.1.
I did all the steps, but the build number remains the same after building.

screenshot at may 17 12-45-35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment