Weekly Swift articles, podcasts and tips by John Sundell.

Generic type aliases

Published on 28 Mar 2018
Basics article available: Generics

A cool thing about Swift type aliases is that they can be generic! Combine that with tuples and you can easily define simple generic types.

typealias Pair<T> = (T, T)

extension Game {
    func calculateScore(for players: Pair<Player>) -> Int {
        ...
    }
}