In Swift, we can make most types decodable by adding the Decodable protocol. While Swift’s default decoding is sufficient in most cases, it leads to issues if simple enumerations are extended later on.

This article demonstrates different approaches how to work around this issue, and highlights the advantages and disadvantages of each approach.

The Problem

Let’s say we are working on an app that allows you to book and pay for different modes of transportation, and we would like to configure from the backend which transport modes and payment methods are shown, and in which order.

We could have an enum for…


In typography, there is the notion of a baseline grid: All the baselines of a text are aligned on invisible lines. Baseline alignment goes back at least 100 years: It is part of the Swiss Style/International Typographic Style.

Baseline alignment still goes strong today: On the web, CSS allows baseline alignment; on Android, baseline alignment is part of Material Design.

📱What about iOS?

Baseline alignment is not the default on iOS: A label takes the space needed for the content, the baselines do not lie on an invisible grid.

At one point, we were asked by our designers whether it would be possible…


Facets of Swift is a series of articles on various aspects of the Swift programming language. At last I have found the time to write the fifth article of this series. As you may have guessed from the title, it’s about custom operators. Operators are closely related to functions, which were the topic of the previous article.

What’s an Operator?

Most programming languages use operators. Simply put, an operator is a symbol or phrase that represents a functionality. For example, i = 1 in Swift uses the assignment operator = which has the functionality of storing the value 1 in the variable i


Facets of Swift is a series of articles on various aspects of the Swift programming language. This fourth article is about functions. I wanted to cover methods as well, but it turned out that functions are such a broad topic they deserved an article of their own.

Anatomy of a Function Declaration

A function declaration in Swift has the following format:

func functionName(parameters) -> returnType {
// statements
}

To understand return types and parameters, it is helpful to know about tuples and tuple types in Swift. If you have read the second article of this series on tuples, great! You’re all set, and you…


Facets of Swift is a series of articles on various aspects of the Swift programming language. This third article is about values and references in Swift. Originally I had planned to write about functions. I chose to write about values and references first as there are a few gotchas related to values in Swift that confuse even seasoned Objective-C developers.

Pass by Value

In C and Objective-C, values are passed everywhere, not references. What does the following code snippet do?

void foo(int i) {
i++;
}
// ...
int x = 1;
foo(x);
printf("%d\n", x);

It will print “1”, as foo gets passed…


Facets of Swift is a series of articles on various aspects of the Swift programming language. I write these articles to organize my thoughts on Apple’s new programming language.

This second article is about Swift’s tuples. Tuples allow us to write more compact code. In addition to that, tuples are a prerequisite to understanding functions, methods and closures, which will be the topic of later articles.

What is a Tuple?

We may remember the concept of tuples from math or computer science. There, a tuple is simply an ordered list of values, where the type of each value is fixed. In Swift, it’s about…


Facets of Swift is a series of articles on various aspects of the Swift programming language. I chose optionals as the topic for the first article, as these are one of the first features of Swift you will notice. The idea of optionals is simple: To prevent errors and to model things in code more accurately, Swift distinguishes between optional and non-optional values.

What are Optionals?

In Objective-C, there is no explicit optional value. To illustrate where that can pose problems, let’s have a look at a method that returns the index of an item in a todo list:

- (NSInteger)indexOfItem:(Item *)item {…

Tammo Freese

Embracing Change.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store