There's also split()
let parts = l.split(separator: ",").map{ $0.split(separator: "=") },
first = parts[0],
second = parts[1]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
My input parsing code was inevitably a mess of stuff like:
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.