---
title: "Chapter 14. Swift"
url: "https://www.mikefluff.com/en/read/beautiful-computer/ch14"
locale: "en"
author: "Mikhail Savchenko (Mike Fluff)"
updated: "2026-11-22T13:46:21.615Z"
book: "https://www.mikefluff.com/en/books/beautiful-computer"
access: "lead-in"
purchase: "https://www.mikefluff.com/en/books/beautiful-computer"
alternates:
  - locale: "ru"
    url: "https://www.mikefluff.com/ru/read/beautiful-computer/ch14"
    markdown: "https://www.mikefluff.com/ru/read/beautiful-computer/ch14.md"
  - locale: "en"
    url: "https://www.mikefluff.com/en/read/beautiful-computer/ch14"
    markdown: "https://www.mikefluff.com/en/read/beautiful-computer/ch14.md"
  - locale: "pt"
    url: "https://www.mikefluff.com/pt/read/beautiful-computer/ch14"
    markdown: "https://www.mikefluff.com/pt/read/beautiful-computer/ch14.md"
---

# Chapter 14. Swift

*[A Lovely Computer](https://www.mikefluff.com/en/books/beautiful-computer)*

I have written in Swift, and in Kotlin too. It was unfamiliar at first, I retrained quickly, I liked the syntactic sugar, the code got shorter and more expressive, and I did not pine for square brackets. Swift suits me. Which makes it all the more interesting to see what my loop of 2011 turns into in it, the one where the name of the method was taken from a database:

```
enum DeviceType { case neo, endpoint }

for dev in devices {
    switch dev.type {
    case .neo:      setNeo(dev)
    case .endpoint: setEndpoint(dev)
    }
}
```

The string from the database is gone. The kinds of device are listed in advance, the switch statement names each of them, and if I add a third kind and forget to write a branch for it, the program will not build, and the compiler will tell me that the switch must be exhaustive. In 2011 I would have learned of the same mistake on the bench, when the new device’s turn came. This is the same switch statement with which the task is solved in Java, and in Swift it does not bother me.

There is no message in Swift by default. When I call a method of an ordinary class written in Swift, the compiler either knows the exact address of the code or takes it from a table made at build time, and no lookup by name happens while the program runs. For a call to go the old way, through `objc_msgSend`, the method has to be marked with the word `dynamic`, and for an object to answer to a name written as a string, its class has to inherit from the old `NSObject`. The empty reference in Swift has also stopped silently accepting anything at all. A variable that may turn out empty has a special type, and the compiler will not let you touch it without stating explicitly what to do in case of emptiness.

---

The rest of this chapter is free on the site once the reader confirms an email address: https://www.mikefluff.com/en/read/beautiful-computer/ch14
