News for hackers. Stuff that matters.
Re:Custom string delimiters in Swift 5 by Mister_Snuggles on Thursday December 27, 2018 @06:26PM (#18773577)
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.

Re:Custom string delimiters in Swift 5 by meggar on Thursday December 27, 2018 @09:44PM (#18774511)
There's also split()

    let parts = l.split(separator: ",").map{ $0.split(separator: "=") },
        first = parts[0],
        second = parts[1]
Re:Custom string delimiters in Swift 5 by msangi on Friday December 28, 2018 @04:57AM (#18775895)
While I agree that String parsing in Swift is quite annoying, when I started using Scanner my Advent of Code parsing experience improved

https://developer.apple.com/documentation/foundation/scanner