Articles, podcasts and news about Swift development, by John Sundell.

Generic type aliases

Published on 28 Mar 2018
Discover page 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 {
        ...
    }
}