Comment

Comment by Mister_Snuggles

I was playing along with Advent of Code and decided to do some of the puzzles, mainly ones where having a graphical view of what's going on would be really nice, in Swift. For reference, the other ones were done in D.

My input parsing code was inevitably a mess of stuff like:

    let parts = l.components(separatedBy: ",")
    let first = parts[0].components(separatedBy: "=")
    let second = parts[1].trimmingCharacters(in: .whitespaces).components(separatedBy: "=")
When I did puzzles in D my input parsing was just creating a regex, matching on it, and pulling out the results.

I started to look at how to do regex in Swift and it seemed easier (!) to just use .components(separatedBy:) as required. Google came up with a number of people who have created libraries/extensions that make this easier, but Swift really needs some better regex handling built in.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton