Matt Coneybeare

MC

Auto-Increment Build Numbers for Multiple Xcode Target Apps

| Comments

Recently, I launched an App called NYC Bikes. Because it quickly became pretty popular, I expanded on it and created another bike share app for Chicago. I then created apps for London, Washington D.C., Melbourne, and San Francisco (all currently under Apple review) with more on the way.

These apps share the same UI, 99% of the same code base, with only API endpoints, colors, strings and images swapped out. I previously wrote about my fix for using Xcode asset catalogs with multiple targets, so I thought I would also share my build number strategy for all of these bike share apps.

If you have been making iOS apps for a while then you probably already have a Xcode run script to auto-increment your CFBundleVersion. It probably reads the Info.plist, adds a num, then writes it back. Something like this:

1
2
3
4
5
6
7
8
# Auto Increment Version Script
buildPlist='YourApp Info.plist'
CFBundleVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$buildPlist")
CFBundleVersionNew=$(($CFBundleVersion + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $CFBundleVersionNew" "$buildPlist"
CFBuildDate=$(date)
/usr/libexec/PlistBuddy -c "Set :CFBuildDate $CFBuildDate" "$buildPlist"
touch "$buildPlist"

This code is fine for one app and I have used it in several projects. But when making multiple targets of the same app like I have on the Bikes project, where each app is 99.9% similar to the others, it makes sense to keep the build versions the same.

This is so that in the wild, when looking at the different apps and build numbers, I can always be assured that the higher build number is the more recent build, even across different bike apps. If I were to increment each app’s build number only when I built that specific project, I would get no information from just looking at the build numbers of two different apps without going back to Xcode and doing a manual lookup of what version was released when.

I will never have to remember which version of which app got the fix to bug X, only that bug X was fixed in build number Y. Then I know which apps in production have the fix applied to it just by looking at the build number.

Thus, I crafted a build run script that is on each target, before compilation.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# set new $IFS
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
FILES="Bikes App/Info/*.plist"
for plist in $FILES
do
    echo "Updating $plist"

    if [[ -z "$CFBundleVersionNew" ]]
    then
        CFBundleVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$plist")
         CFBundleVersionNew=$(($CFBundleVersion + 2))
    fi

    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $CFBundleVersionNew" "$plist"

    CFBuildDate=$(date)

    /usr/libexec/PlistBuddy -c "Set :CFBuildDate $CFBuildDate" "$plist"

    touch "$plist"
done
# restore $IFS
IFS=$SAVEIFS

In English, it looks at all the Info.plist files for the targets, calculates the new bundle version if I haven’t already, then sets it on the plist along with the current date. The bash junk up top just tells the for loop to handle whitespace properly in the file list.

If you are paying attention you will also note that I increment the version by 2, not 1. This is because I particularly like odd-numbered build versions. It makes no logical sense, but I feel that even-numbered build numbers have the tendency to look fabricated. I would rather release a version that just happened to be 5001 rather than 5000, so I start new Apps at 1001 and auto-increment by two from there on every build. Enjoy!

Lastly, I run a small software company called Urban Apps. It pays the bills so I can take the time to write helpful posts like this. If you found this posting helpful at all, I would really appreciate it if you would check out my Apps on the iTunes App Store.

Comments

My name is Matt Coneybeare, I design and develop for iOS (iPhone, iPad and iPod Touch), Mac OS X and the Web out of New York. In 2008 I started a software company called Urban Apps that has made some pretty popular apps such as Ambiance and Hourly News. My current Stack Overflow reputation is about 27k.

I was a Rockstar a decade ago, but then went back to school and collected a Bachelor's Degree in Computer Science from U.C. Berkeley. Now I am settled down with my beautiful wife Di and our two doggies Hamachi and Foxy. While coding, I walk several miles/day on my Treadmill Desk. When not at my desk, I love exploring New York City as a Yelp Elite, or training for marathons.

Contact information

Name
Matt Coneybeare
Email
Website
Twitter
Instagram
GitHub
Google+
LinkedIn