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

Lightweight data hierarchies using tuples

Published on 16 Jul 2018

Here I'm using tuples to create a lightweight hierarchy for my data, giving me a nice structure without having to introduce any additional types:

struct CodeSegment {
    var tokens: (
        previous: String?,
        current: String
    )

    var delimiters: (
        previous: Character?
        next: Character?
    )
}

handle(segment.tokens.current)