Developing software in the Real World

Introducing SwiftDotEnv

Regardless of which language you use, there are always configuration settings that need to be handled. One of the tenets of twelve factor app is that config should be stored in the environment. This is easy enough on the command line or in the config of our preferred hosting solution. When developing locally without a VM however it gets a little more complicated as we may need the same environment variable set to different values… continue reading.

Ctags with Swift

I always seems to end up in vim sooner or later and I use Tim Pope's excellent Effortless Ctags with Git process to keep my ctags file up to date for my projects. As I'm now coding in Swift too, I needed ctags to support Swift. This is what I've added to my .ctags file:

Any improvements, welcome! vim.swift As I'm writing about Swift and vim, I should also point out that the vim-swift… continue reading.

Cross-platform Makefile for Swift

I'm mostly building Swift applications for deployment to Linux, but sometimes it's easier to build and test directly on OS X rather than spinning up a VM. To facilitate this, I use a Makefile that means that I don't have to remember the compiler switches. It looks like this:

Let's go through it.

This simply sets which version of Swift this project uses. It's up the top as this is the only line… continue reading.

swiftenv: Swift version manager

Swift 3 development is so fast at the moment, that a new development snapshot is coming out every couple of weeks. To manage this, Kyle Fuller has rather helpfully written swiftenv which works on both OS X and Linux. Once installed, usage is really simple. To install a new snapshot:

Where {version} is something like: DEVELOPMENT-SNAPSHOT-2016-05-09-a, though you can also use the full URL from the swift.org download page. The really useful feature of… continue reading.

Compiling Swift on Linux

Swift is open source, which means that we can build it ourselves. This isn't too hard to do, but takes some time. Set up the dependencies and grab the code Firstly, you need a lot of memory and as it takes ages, give your VM plenty of CPUs! My Macbook Pro has a quad core process, so I tell Virtualbox that it can use all 4 using this configuration in my Vagrantfile:

You then… continue reading.

Easily install Swift on Linux

This is the simplest set of steps that I've found so far in order to get Swift on (Ubuntu) Linux. Essentially, you can download a snapshot and you're good to go. If you're not already on Ubuntu 15:10, create a VM. Vagrant is an easy way to do this:

Install the dependencies:

(Vim isn't an actual dependency, but I can't cope with terminal that doesn't have it!) Grab a Swift snapshot & untar:… continue reading.

Unit testing with Swift PM

As I tend to work with Swift on Linux, I've been working out how to unit test using the Swift Package manager. This article is my way of remembering what I've learnt so far! Let's do this in the context of writing an a Todo entity from the Todo-Backend project. Create a package Creating a package is easy with Swift PM:

(you can replace library with executable when creating an app) When you run… continue reading.

Getting started with Zewo

Zewo is a set of Swift packages that enable writing HTTP services. Most of the packages are focussed around this goal, but it also includes adapters for MySQL and PostgreSQL which is useful. The HTTP server is called Epoch and you can combine it with Router and Middleware to make a working API. To get going I wrote a simple /ping end point to see how it fits together. Epoch is built on libvenice (a… continue reading.

Function pointers in my Swift CCurl library

By default, libcurl writes the data it receives to stdout. This is less than useful when writing an application, as we want to store the received data internally and process it. This is done using the libcurl settings CURLOPT_WRITEFUNCTION which takes a function pointer where you can process the received data and CURLOPT_WRITEDATA which lets you set a pointer to something that can store the received data. You get access to this pointer within your… continue reading.

Wrapping variadic functions for use in Swift

As I noted in my post about getting libcurl working with Swift, curl_easy_setopt() is a variadic function which means that Swift will not import it. If you try to use it you get this error:

It's mildly annoying as curl_easy_setopt only ever takes three parameters! I assume that it's marked as a variable argument function because the last parameter can be any type? To solve this, I wrote a simple C library that exposes… continue reading.