First Impressions of Fastlane Swift for iOS
Fastlane, a tool for automating iOS deployments, now has Swift support from version 2.69.0 onward. Here, you'll find one developer's perspective.
Join the DZone community and get the full member experience.Join For Free
fastlane has just been released, with swift support from version 2.69.0 onwards, which means ios developers no longer have to write ruby code to configure fastlane in ios or macos projects. fastlane is one of the great tools to automate ios deployments, releases and all sort of common ios development tasks like code signing, managing provisioning profiles, certificates and versions from apple developer portal. fastlane provided programmatic implementation to automate all these tasks so that we can set up continuous integration and continuous delivery on any ci server. however, ios developers have to learn and write some ruby code in order to configure fastlane in the project which is one of the obstacles of using fastlane effectively. traditionally ios developers are skilled in objective-c or swift but not in scripting languages like bash, ruby, python. fortunately, fastlane has announced swift support so that we can use apple's swift programming language to configure ci/cd setup for ios app. in this post, i will share my first impressions of using the swift version of fastlane.
fastlane has added brief documentation of how to get started with fastlane swift here but we will see how it looks in action. the first thing to notice is that even though fastlane has provided swift support, it is still packaged as rubygem ; you still have to install fastlane using rubygem using the following command:
$ gem install fastlane
this might take few minutes to install all required dependencies. you might need to use
if you are using system ruby that comes with default macos. once installed, we have to make sure you have fastlane version above 2.69.0 to work with swift. we can check that using the
now, let's create a single view ios project fastlaneswift-demo in xcode. in order to check cocoapods support let's add some dependencies in podfile. now we will initiate fastlane for this project using the following command:
$ fastlane init swift
this will set up our project as usual by asking some questions about your credentials, app identifiers, and schemes and you should be able to complete setup easily.
once everything is finished, you will see the message saying to open xcode project located at:
this is an additional xcode project in order to configure fastfile inside xcode with all the autocompletion and syntax highlighting. at this point, you are good to use swift for configuring lanes. however, if you want to see what has just happened, you may notice that fastlane has created 8 directories and 34 swift files inside the
now, let's open the xcode project fastlanerunner.xcodeproj in order to understand what's inside. we will see a project structure like this:
we can see that all the configurations like fastfile are now written in swift. now we can create lanes using swift methods. we can all the available fastlane
straight withing lanes. now, let's configure our unit and ui tests to run with fastlane. as you can see, fastfile has already created the lane
to run tests that we can execute directly using
$ fastlane testlane
this will run all the available tests configured for the specific scheme. as you might remember from ruby version that, fastlane uses
in order to run unit or ui tests. let's see how we can configure scanfile using the swift version. there are two files created
as a template, having all the options that can be configured and
has template code where we can configure our options. let add following options to scanfile.
now that, we have configured our scanfile and we can run the lane with our configured file.
you can see in the gif above that we have all the autocompletion and syntax highlighted while writing configuration. also, note that we can run tests using that configured lane, but we have to manually select the scheme each time.
configure continuous integration
we can test this on cloud-based continuous integration services like travisci if you are using github. we just have to create a file (
) and add the following:
language: objective-c osx_image: xcode9 before_install: - gem install fastlane --no-ri --no-rdoc --no-document install: true script: - fastlane testlane
now that we can enable project on travis and start running the builds on travisci.
demo project and travisci
the way i understand how fastlane swift is implemented is as follows:
- fastlane swift is a swift wrapper to execute ruby commands under the hood.
- all the scan, match gym options are created using respective protocols and extensions.
all the fastlane actions are stubbed into a massive
fastlane.swiftfile which runs ruby commands.
- fastlane logs can clearly show that all the bunder and rubygems are still executing under the hood.
fastlane swift has just been born, so it would be unfair to say pros and cons, but consider this as my first impressions of fastlane swift.
- ios developers no longer have to use ruby code to configure the ci/cd of ios apps.
- the xcode project has provided autocompletion and syntax highlighting for all available fastlane actions.
- the code is purely in swift so can be compiled and deployed easily.
- every ios developer can now understand fastlane easily.
it's too early to write about its cons, but what i feel is
- fastlane swift is just a wrapper which adds 38 unnecessary swift files to the ios project, including the xcode project.
- fastlane should have come up with an sdk that can be installed using cocoapods, carthage, or swift package manager.
- the little issue is that scanfile configuration is not respected, as i have to input a scheme manually. or have i done something wrong/misunderstood?
- when i want to do any fastlane action, the method takes millions of parameters. it would be great to have a separate config file.
- having an additional xcode project might confuse some cloud-based ci services like buddybuild or bitrise, as they build that project as well on top of the normal ios app.
- it's too early, and it's not purely the swift implementation of fastlane, it just wraps up ruby commands under the hood.
fastlane has made a great improvement by adding swift support, and huge thanks to this contributor , it might be game changing in the future. however, my personal opinion is that the configuration has to be configuration and should be written using config files and scripting languages. unfortunately, swift isn’t the scripting language, but it’s everyone’s personal choice. until fastlane swift matures, i will stick with the ruby version. what is your opinion? i would recommend every ios developer to give it a try. please correct me if i am missing anything in this post.
Published at DZone with permission of Shashikant Jagtap, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.