“\r\n” is one Character in Swift

From the department of “how did I not realise this sooner?!”: Yes, Swift treats the two bytes “\r\n” as a single character.  This is actually super convenient a lot of the time, because it means algorithms that look for line breaks with isNewline just work, even on “Windows”-style text.  Otherwise, you’d have to explicitly look… Read more

Matching prefixes in Swift strings

How do you determine if one string starts with another, in Swift? Surely that’s exactly what the hasPrefix(_:) method is for: No can haz etiquette? Wot? The problem is that hasPrefix is not meant for general use with human text; it’s barely better than a byte-wise comparison. It only guarantees that it won’t be fooled… Read more

Flinging poo in Swift

Thanks to one of the genuine upsides of Swift, full Unicode support in the compiler itself, you can do: Finally you can express yourself honestly within your program: Or, if you prefer to be polite & British about it: You can go further, if you like, and have all manner of interesting things thrown about… Read more