Testing ok under Xcode 11.4.1
Credit goes to Sekati's gist
In xcode 5, select Editor -> Add Build Phase -> Add Run Script Build Phase
And then drag the added phase under Link Binary with Libraries
####Increment build number on building
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
####Increment version number on archiving
and select Run script only when installing (would effect )
VERSIONNUM=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")
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" "${PROJECT_DIR}/${INFOPLIST_FILE}"
Note:
- The above is only valid when initiating (build, archive) from Xcode
- Make sure the initial build number is integer. (Ex. 1, or 0)
- PlistBuddy is the helper tool to read and write values to plists