Swift on the Raspberry PI
TOC
1. Why
2. Building
3. GPIO
4. Tools
Why?
Just
another
language
Just
another
good
language
Advantages
4 Expressive
4 Fast
4 Memory-efficient
4 C-compatible
Downsides
4 Not a real platform (such as Android Things)
4 Not many drivers
4 ARM Linux not officially supported by Apple (yet)
Building
Requirements
4 Raspberry PI 3
4 Micro-SD Card (8 or 16 GB)
4 Ubuntu Core (+ Ubuntu SSO Account) or Raspbian
4 External Screen (just for first booting)
4 HDMI Cable !
1. Ubuntu Core
1. Create an Ubuntu SSO Account
2. Read https://developer.ubuntu.com/core/get-
started/raspberry-pi-2-3
3. Install on the micro-SD card
4. ssh <USERNAME>@<RASPBERRY-IP>
2. The "Classic" mode
1. sudo snap install classic --edge --devmode
2. sudo classic
3. Building Swift
6 HoursFrom sources
3. (not) Building Swift
(The I've-just-got-30-minutes way)
$ http://swift-arm.ddns.net/job/Swift-3.0-Pi3-ARM-Incremental/
lastSuccessfulBuild/artifact/
swift-3.0-2016-12-21-RPi23-ubuntu16.04.tar.gz
or
$ wget https://www.dropbox.com/s/cah35gf5ap22d11/swift-3.0.2-RPi23-1604.tgz
Courtesy of @uraimo
4. Dependencies
$ sudo apt-get install -y libpython2.7 libxml2 libicu-dev clang-3.6 libcurl3
$ sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
$ sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100
5. All set!
$ swift --version
> Swift version 3.0.1-dev (LLVM a922364e5b, Clang 968470f170, Swift 0cca6668a2)
Resources
4 http://viteinfinite.com/2017/02/swift-on-the-
raspberry-pi-part-1/
4 http://dev.iachieved.it/iachievedit/building-
swift-3-0-on-an-armv7-system/
4 https://www.uraimo.com/2016/12/30/Swift-3-0-2-
for-raspberrypi-zero-1-2-3/
GPIO
4 https://github.com/uraimo/SwiftyGPIO
let package = Package(
name: "MyProject",
dependencies: [
.Package(url: "https://github.com/uraimo/SwiftyGPIO.git",
majorVersion: 0),
]
)
A basic example
import SwiftyGPIO
let gpios = SwiftyGPIO.GPIOs(for:.RaspberryPi2)
guard var gpio2 = gpios[.P2], var gpio3 = gpios[.P3] else {
return
}
gpio2.direction = .IN
gpio3.direction = .OUT
while true {
gpio3.value = gpio2.value == 1 ? 0 : 1
}
Tools
SourceKitten
SwiftKitten + rsub
SwiftKitten + rsub
ssh -R 52698:localhost:52698 <user@remoteHost>
$ rsub file.swift
Resources
4 https://github.com/johncsnyder/SwiftKitten
4 https://github.com/Drarok/rsub
That's (almost) all!
SwiftyGPIO
SwiftyGPIO

SwiftyGPIO