Swift beyond Apple

A survey of tools from the evolving Swift open source community.

By Paris Buttfield-Addison
January 12, 2016
Hummingbirds and Swifts detail Hummingbirds and Swifts detail (source: Pixabay)

In the last two posts about Swift’s open source release, we talked quite a bit about the past and present of Swift, especially in the context of things that are under Apple’s control. In this blog post, we’re going to take a look outside of the Apple universe, and look at how Swift’s starting to be used in the wider world.

One of Apple’s biggest corporate partners, IBM, was very quick to announce and release their IBM Swift Sandbox, a cloud-hosted environment for programming Swift. The Swift Sandbox is very similar to other web-based live coding environments, like Code School’s Try Ruby, but with an interesting twist: the Swift Sandbox is downloadable as a Docker container, allowing you to host the same application on your own hardware.

Learn faster. Dig deeper. See farther.

Join the O'Reilly online learning platform. Get a free trial today and find answers on the fly, or master something new and useful.

Learn more

When IBM launched the Swift Sandbox, Nasdaq described it as “a Swift move.” We just wanted to let that hang there for a moment, to make sure that you’ve got time to get that joke. Once you’re satisified with that nugget of hilarity, please continue reading.

One of the most important facets of the Swift open source release is that it includes an implementation of Swift’s libraries for Linux. This is staggeringly important for Swift to take hold as a language for server development, and we’re starting to see a number of projects that specifically target Linux.

There are two especially good examples of this in action. Caramel for Swift is a support library for applications designed to run on servers. In particular, Caramel is a library that provides the majority of server-specific file and networking functionality.

Caramel is designed to act as a replacement for several critical portions provided by Apple’s Foundation library; however, Caramel is not designed to be a simple re-implementation of this library. Caramel is instead an attempt to create a “Swift-style” approach to this problem domain, unencumbered by the traditions of older, existing libraries. At the time of writing, Caramel isn’t yet production ready, but it’s an example of the type of projects that the decoupling of Swift from Apple platforms permits.

While Caramel is designed for general server application development, a lot of server apps are apps that communicate over HTTPS, either with a mobile client or a web browse based frontend. Perfect is one of the first, and certainly one of the most polished, frameworks for developing application backends in Swift.

The goal of Perfect is to maximize code reuse between the client and the server. When using Perfect, a core library of what suits call “business logic” is built and embedded in both the server binary and the client iOS app; this shared module is responsible for serializing and deserializing the model objects that are sent back and forth between the two halves of the app.

If you’d prefer a more lightweight framework for building your backend, Taylor is a very simple library that lets you build web apps using straightforward DSL that’s very reminiscent of frameworks like Sinatra and Flask. Using Taylor, you can very quickly spin up a simple little remote API for your application.

If you’re interested in getting started with server-side Swift, a great way to create a development environment for playing with Swift is to use Docker to create a container (we mentioned this earlier). An excellent resource for this is IBM’s tutorial, in which you create and set up a container that hosts both the Swift binaries as well as the standard library. Using this as a base, you can use the Swift package manager (mentioned in the last post), and its rapidly expanding collection of available third-party packages, to create your setup.

It’s worth pointing out that the landscape for Swift server development is still quite immature. None of this is production ready yet, but the enthusiasm of the community has been something to behold. Don’t jump straight into Swift yet if you need to create a bullet-proof, enterprise grade server application; that said, this early stage of Swift’s expansion into server development is a great time to see things evolve right in front of your eyes. Give it a few months.

Swift is production ready is on Apple’s platforms, and we’d be remiss if we didn’t take the opportunity to plug our book, Learning Swift. While it does focus on Apple platforms (iOS, OS X, and watchOS), we think it’s a pretty great resource for both becoming familiar with the Swift language and getting comfortable using it to build real-world applications, with actual features.

We hope that you’ve enjoyed this dive into the background and implications of the Swift open source release. We’re tremendously excited about the future of Swift; while Apple has always indicated that there’s a lot of support behind Swift for the platforms they control, the broader applicability of Swift means that the future is bright for this excellent little language.

Post topics: Open Source
Share: