24 May 2018
iOS and macOS apps have a version number and a build number. Typically you see these in Xcode or iTunes Connect represented something like this:
1.0 (1)
This is version number 1.0
, build number 1
As I’m sure you know, the build number is used to differentiate different builds of the same version, so you might upload build 1
, then make amendments, and then upload build 2
I used to manually increment this build number each time I created a build, but that strategy has it’s problems:
The last point is the most important. How do you know that you have the right build? QA might tell you that they found a problem on build 8
… which one was that again? Or you’re submitting your app on iTunes Connect, and the build is 9
- was that the one you just created or not?
Recently I’ve been using a timestamp (yyyyMM.dd.HHmm)
for my build numbers, which looks like this:
1.0 (201805.15.1407)
This build was created on 15/05/2018 at 14:07
Note that you can only have three periods in the build number, which is why I’ve put the year and month together
This has some great benefits:
This is pretty easy to achieve using a ‘Run Script Phase’ in Xcode’s build phases with the following script:
# Generate the build number using current date and time buildNumber=$(date "+%Y%m.%d.%H%M") # Set the build number in plist file /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"