Veedrac Veedrac - 2 months ago 19
Swift Question

What kind of normalization is used by Swift string comparisons?

Elsewhere I've seen it told that Swift's comparisons use NFD normalization.

However, running in the iSwift playground I've found that

print("\u{0071}\u{0307}\u{0323}" == "\u{0071}\u{0323}\u{0307}");


gives
false
, despite this being an example straight from the standard of "Canonical Equivalence", which Swift's documentation claims to follow.

So, what kind of canonicalization is performed by Swift, and is this a bug?

Answer

It seems that this was in bug in Swift that has since been fixed. With Swift 3 and Xcode 8.0,

print("\u{0071}\u{0307}\u{0323}" == "\u{0071}\u{0323}\u{0307}")

now prints true.