Edit (April 2019): The original post was written in January 2017 back in the Swift 3.0 days when Linux support was still young. As of this edit Swift is on the 5.0 release and Linux support is much better then it used to be. If you are looking for up to date information about Swift on Raspberry Pi and precompiled Swift binaries that you can use on the system I recommend visiting Umberto Raimondi blog. Once I will have more time, I will update this post with new information.

Recently I became interested in writing software that would interface with external hardware devices like sensors or motors. One of the easiest ways to interact with external hardware is through a Raspberry Pi. The small computer has 40 GPIO pins that will let you connect it to external devices. About a month ago I bought a Raspberry Pi to see what I can do with it.

Photo from raspberrypi.org

By day, I am an iOS developer, developing mobile apps for startups. Most of the apps I create nowadays are written in the Swift programming language.

I love Swift. The new Apple language is modern, safe and expressive. While the speed of development may not be on par with a scripting language such as Python, the static type system makes the overall application more safe and robust. Since I am very well versed in Swift, I wanted to explore its support for the Pi. Here is what I found so far.

Swift logo taken from apple.com, Raspberry Pi logo from raspberrypi.org

There are two main components needed to write Swift on the Raspberry Pi:

A Swift compiler and package manager for the platform

A Swift library for GPIO support

Although Apple does publish precompiled Swift binaries with support for Linux, it only supports platforms with x86 processors. There is no official support for ARM devices such as the Raspberry Pi. But Swift is open source and with the incredible work of some dedicated contributors, the Swift compiler was ported to ARM systems.

Umberto Raimondi recently published Swift 3.0.2 precompiled binaries that work on the Pi. I had problems with the Raspbian version since the Package Manager was broken there. But once I installed Ubuntu Mate and then the Swift Ubuntu binaries everything was working fine.

Umberto is also the author of a GPIO library written in Swift. You can install the library using the Swift Package Manager.

Using the above infrastructure I was able to run my first Swift program to light up an LED using GPIO pins on the Raspberry Pi.

Raspberry Pi running Swift code to light up a LED!

Conclusion:

Swift support on the Raspberry Pi is still very experimental and driven by a dedicated group of open source contributors. Hell, even Linux support is on a very early stage since the core libraries like Foundation are not fully ported to the OS. There is no IDE support, and at first, I was editing my programs in nano which was not a pleasant experience.

But Swift on the Pi is usable and if you want to play around, you should be able to set it up pretty quickly. Let’s hope Apple will one day officially support the ARM platform so we can deploy the full power of Swift with confidence!