Consistent versioning in iOS projects

You start off with a version number on you app’s splash screen. Then, perhaps later you add a Setting bundle and want a version there, or on an in-app profile screen. At some point you realize your logging would be more useful if it had a logged the version info when the app started up. Now you need something to keep these versions all in sync and to easily update them.

I created a auto versioning script for Xcode for use in iOS and OS X projects to solve this. It’s available on github and is called Auto Version Xcode. It uses the versioning you put in your General tab in Xcode to drive versioning in your app

This script generates a version.swift (or version.h file if you’re using Objective C) with several different formats of your app version (with varying detail). It also makes other constants with your app name, configuration, copyright, and Xcode & SDK information. All this has been useful in either identifying or debugging apps in the past. You can use these contants in your code internally, in logging, or for user display on screens.

The script is run early at build time, the readme has the install/use information. It creates a file that should not be put into git as it’s recreated each build. The file is version.h for Objective C or version.swift for Swift that defines a number of build-time constants to be used in your app for logging or other purposes. And there’s different ways of showing the versions like:

let FullVersion = “1.0.0b1–2-F3380-dirty”

let Version = “1.0.0b1”

let SimpleVersion = “1.0.0”

The version is set in the project’s plist file and can be easily set in the project’s General tab (above). In the above case, I set “1.0.0b1” and the script generated the above for build 2 of beta 1 with the commit hash of F3380 and the code is “dirty” which means that something needs to get checked into git.

This script also has project environmental information like SDK name, Xcode version, and deployment target. It also has the application name and configuration (release or debug). You can use it to handle copyright name and year too if you like.

Instructions are in the comments in the script. It should be clear on how to use. Let me know if this is as handy for you as it is for me!

Like what you read? Give Malcolm Teas a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.