Automation DevOps iOSDev

Ensuring Swift version using Fastlane Plugin

Apple made Swift open-source in December, 2015 and since then new version of Swift getting released frequently. In these changing environment of Swift development, it’s essential to make sure version of the Swift being used to build iOS apps are correct and as expected. We will cover how to automatically check version of Swift using Fastlane plugin I wrote called ‘ensure-swift-version‘.

Why to Check Swift Version

As per the Github releases on Swift repository, we can see that new DEVELOPMENT-SNAPSHOT being released almost everyday. We can swift to different toolchain of the Swift easily to try out new features of the Swift language. There are information about the using custom toolchain on the Swift documentation page here.

Swift Version

We can check version by running   swift --version command from terminal however we have to plug this step into our build process. Fastlane is one of the popular tool being used for build automation of the iOS apps. I thought, it would be great idea to add plugin to Fastlane to check Swift version. Let’s see how to add plugin to project use it.

Add Fastlane Support to Project

Let’s create a new Xcode project as single view iOS application. Let’s call it ‘Demo’

We can add Fastlane support to the project by creating Fastfile  inside fastlane directory.

Add Fastlane Plugin

Assuming you already have fastlane installed on your macOS, if not then follow the installation steps from documentation here. We can add fastlane plugin by running

This will setup Gemfile and Pluginfile for our project and install the plugin ‘ensure-swift-version‘.

Use Plugin

Now that, we can use our newly added plugin. Let’s add a lane in our Fastfile

Here, we are checking that we are using our Swift version is 3.1. We can execute lane using

As we can can see, how easy it would be to plug this check into our build process. It’s ideal to use  this check as part of the before_all  lane so that we can perform this check before building and testing our app.

Example Code

The plugin is available on Github repo ‘fastlane_plugin_ensure_swift_version‘ and there is demo repo for usage of this plugin ‘demo_ensure_swift_version_plaugin’

Hope you find this plugin useful.