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?
When Data Normalization is done correctly, standardized data entry is the result. This technique, for example, applies to the recording of URLs, contact names, street locations, phone numbers, and even codes. These standardized data fields can thus be quickly grouped and read.
Sponsor sarunw.com and reach thousands of iOS developers. In Swift, you can check for string and character equality with the "equal to" operator ( ==) and "not equal to" operator ( != ). We use the same operator for Character. These "equal to" operator is suitable for simple string comparison where you required an exact match.
These anomalies are not good for referential integrity (or for data integrity in general). In a normalized database, the data is usually arranged independently of the users’ desired view of that data. This is one of the principles of relational database design.
Here’s an example of a normalized database schema: A basic schema diagram of a normalized database. This schema separates the data into three different tables. Each table is quite specific in the data that it stores – there’s one table for albums, one for artists, and another that holds data that’s specific to genre.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With