Xcode - use incrementing buid numbers
26/02/16 21:40
Incrementing build numbers in Xcode is actually fairly easy once you have the proper script to run.
This is something that all Xcode projects should have since it makes life way easier when submitting multiple builds to iTunes Connect, or even for direct versions that use Sparkle for updating.
For example, a version number might be 1.5 (25), and once it's built again it will become 1.5 (26). How's how:
Step 1 - Update the Build number to be a number without any decimals
- Select the project row in Xcode.
- Select the target that this will apply to.
- Select the General tab.
- For the Identity -> Build, choose a number without any decimals. For example, 1, 1000, 343, etc.
Step 2 - Add the script that will increment the build number
- Select the Build Phases tab.
- Click the plus icon to add a "New Run Script Phase"
- Paste the following into the script:
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
It should now look like this:
Step 3 - Try building the project
Build the project and watch the build number increase each time. It's like magic.
This is something that all Xcode projects should have since it makes life way easier when submitting multiple builds to iTunes Connect, or even for direct versions that use Sparkle for updating.
For example, a version number might be 1.5 (25), and once it's built again it will become 1.5 (26). How's how:
Step 1 - Update the Build number to be a number without any decimals
- Select the project row in Xcode.
- Select the target that this will apply to.
- Select the General tab.
- For the Identity -> Build, choose a number without any decimals. For example, 1, 1000, 343, etc.
Step 2 - Add the script that will increment the build number
- Select the Build Phases tab.
- Click the plus icon to add a "New Run Script Phase"
- Paste the following into the script:
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
It should now look like this:
Step 3 - Try building the project
Build the project and watch the build number increase each time. It's like magic.
blog comments powered by Disqus