Tunabelly Software

Xcode - use incrementing buid numbers

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 +
/usr/libexec/PlistBuddy -c
"Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"

It should now look like this:

Screen Shot 2016-02-26 at 9.51.27 PM

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