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)

Support Swift by Sundell by checking out this sponsor:

Essential Developer

Essential Developer: If you’re a mid/senior iOS developer who’s looking to improve both your skills and your salary level, then join the iOS Architect Crash Course, starting on January 31st. It’s 100% free and held entirely online. Click to learn more.