How to increase your Build Number automatically every time you build your Xcode Project

Xcode includes something rather magical called the Apple Generic Versioning Tool. With this tool you can increase your Build Number automatically every time you hit “Build and Run” in Xcode.

Here’s how you can add it to your project. I’m using Xcode 5.1 here with a new Single View iOS project. But this will work just fine in other versions of Xcode.

By default, Version and Build are set to 1.0 (in your app target, under the General tab). We want to leave Version alone and only increase Build.

Screen Shot 2013-12-30 at 12.05.06

Head over to the Build Settings tab and find the “Versioning” section. It’s easiest to just search for it. In here, set the Current Project Version field to your initial build – let’s say 1 for this example.

Screen Shot 2013-12-30 at 12.10.10

Now select the Build Phases tab. Click on the little plus icon in the top left corner and select New Run Script Build Phase. This will allow us to execute a small script every time we build.

Screen Shot 2013-12-30 at 12.11.39

Open the little triangle next to Run Script and underneath the Shell field, add this bit of code. You can even add multiple lines, it’s like a little text editor.

"${DEVELOPER_BIN_DIR}/agvtool" next-version -all

Here’s what it should look like:

Screen Shot 2013-12-30 at 12.15.03

And that’s it! Hit CMD+B a few times and head back to the General tab to see your Build Number magically increased. You can now retrieve this value from you main Bundle (explained in my previous article).

Kudos to nekno who was kind enough to share this knowledge on Stackoverflow:

You can leave a comment on my original post.