Why are emoji characters like ๐ฉโ๐ฉโ๐งโ๐ฆ treated so strangely in Swift strings?
3 min readOct 6, 2020
This has to do with how the String
type works in Swift, and how the contains(_:)
method works.
The โ๐ฉโ๐ฉโ๐งโ๐ฆ โ is whatโs known as an emoji sequence, which is rendered as one visible character in a string. The sequence is made up of Character
objects, and at the same time it is made up of UnicodeScalar
objects.
If you check the character count of the string, youโll see that it is made up of four characters, while if you check the unicode scalar count, it will show youโฆ