Incrementing Build Numbers in Xcode

(This was originally posted in April of 2009 and has been reposted here for posterity)

I admit, I’m a sucker for numbers. When I release a project, it’d be kind of cool to know how many times I’ve built it. With that in mind, and with a good deal of help from my friend Quinn and a couple of online tutorials, I was able to come up with a neat little script that can do just that.

Here’s what you need to do:

  1. Select the target you’re working with, and add a new “Run Script Phase” to it
  2. Paste the following code into the script box:

     buildNumber=$(/usr/libexec/PlistBuddy -c "Print DDBuildNumber" Info.plist)
     buildNumber=$(($buildNumber + 1))
     /usr/libexec/PlistBuddy -c "Set :DDBuildNumber $buildNumber" Info.plist
  3. Compile with impunity

The idea is simple: It uses your project’s Info.plist file to store an integer value under the key “DDBuildNumber”. Every time you build, it grabs that number, increments it, and saves it back to the plist.

A caveat: It seems like Xcode is caching Info.plist, so you may not see the change reflected immediately in Xcode. However, if you open Info.plist from the Finder (or just Quick Look it), you’ll see that the number has changed.

Related️️ Posts️

The Missing Accessory
Building a Cross-Platform Framework
The Laws of Core Data
A Better MVC, Part 5: An Evolution
If iPads were meant for kids
Apple Networking Feedback
Swift Protocols Wishlist
Simplifying Swift framework development
Reading your own entitlements
A Better MVC, Part 4: Future Directions
A Better MVC, Part 3: Fixing Massive View Controller
A Better MVC, Part 2: Fixing Encapsulation
A Better MVC, Part 1: The Problems
Keynote's awesome Outline Mode
iOS Feature Wish: Contact Provider Extensions
Every beginning has an end