Pragmatism 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: –langdef=Swift –langmap=Swift:+.swift –regex-swift=/(var|let)[ \t]+([^:=]+).*$/\2/,variable/ –regex-swift=/func[ \t]+([^\(\)]+)\([^\(\)]*\)/\1/,function/ –regex-swift=/class[ \t]+([^:\{]+).*$/\1/,class/ –regex-swift=/protocol[ \t]+([^:\{]+).*$/\1/,protocol/ Any improvements, welcome! vim.swift As I'm writing about Swift and… 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: # This Makefile assumes that you have swiftenv installed # To get going, start with `make init` SWIFT_VERSION = DEVELOPMENT-SNAPSHOT-2016-05-03-a # OS specific differences UNAME =… 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: swiftenv install {version} 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… 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: config.vm.provider "virtualbox" do… 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: $ vagrant init ubuntu/wily64 $ vagrant up $ vagrant ssh Install the dependencies: $ sudo apt-get install clang libicu-dev vim (Vim isn't an actual dependency, but… 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: mkdir Todo cd Todo swift build –init library (you can replace library with executable… 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: error: 'curl_easy_setopt' is unavailable: Variadic function is unavailable curl_easy_setopt(handle, CURLOPT_VERBOSE, true) ^~~~~~~~~~~~~~~~ CCurl.curl_easy_setopt:2:13: note: 'curl_easy_setopt' has been explicitly marked unavailable here public func curl_easy_setopt(curl: UnsafeMutablePointer, _ option: CURLoption, _ varargs: Any…) -> CURLcode ^ It's mildly annoying as curl_easy_setopt only… continue reading.