Language
Swift
- First appeared
- 2014
- Paradigm
- Multi-paradigm, compiled, statically typed
- Toolchain
- Swift 6.0.3
- Container image
debian:trixie-20261027-slim + swiftlang 6.0.3-2
Apple introduced Swift in 2014 as the successor to Objective-C, and it’s now the main language for apps on the iPhone, iPad, and Mac. It’s open source and runs on Linux too, which is how it runs here. It aims to be safe by default: values can’t be missing unless their type says so, integer overflow stops the program instead of wrapping, and arrays are copied, not shared.
The implementations use Swift’s standard library plus Foundation, which ships with the compiler and is how Swift reads files and formats numbers on every platform. Neither has statistics or matrices. Packages from the Swift Package Manager, such as Swift Numerics, aren’t installed. The compiler treats every warning as an error.
Quirks
IntandDoublenever mix on their own:1.5 / nwith anIntnis a compile error, so you write1.5 / Double(n).- Integer overflow crashes the program.
&+wraps on purpose:Int.max &+ 1is −9223372036854775808. - You can’t index a string by number:
s[0]won’t compile."café".countis 4 characters, while"café".utf8.countis 5 bytes. - Arrays are values. After
var b = aandb[0] = 99,ais unchanged. -7 / 2is −3, rounding toward zero.
Concepts in Swift
- Cross-validation
- Decision tree
- Descriptive statistics
- k-means clustering
- k-nearest neighbors
- Linear regression
- Logistic regression
- Naive Bayes
- Principal component analysis
Run the examples locally
You need Docker and Python 3. The harness builds the pinned container and runs every Swift example:
git clone https://github.com/qnixon/dswithx.git
cd dswithx
python3 harness/run_tests.py --language swift