The character π©βπ©βπ§βπ¦ (family with two women, one girl, and one boy) is encoded as such:
U+1F469
WOMAN
,
βU+200D
ZWJ
,
U+1F469
WOMAN
,
U+200D
ZWJ
,
U+1F467
GIRL
,
U+200D
ZWJ
,
U+1F466
BOY
So itβs very interestingly-encoded; the perfect target for a unit test. However, Swift doesnβt seem to know how to treat it. Hereβs what I mean:
"π©βπ©βπ§βπ¦".contains("π©βπ©βπ§βπ¦") // true
"π©βπ©βπ§βπ¦".contains("π©") // false
"π©βπ©βπ§βπ¦".contains("\u{200D}") // false
"π©βπ©βπ§βπ¦".contains("π§") // false
"π©βπ©βπ§βπ¦".contains("π¦") // true
So, Swift says it contains itself (good) and a boy (good!). But it then says it does not contain a woman, girl, or zero-width joiner. Whatβs happening here? Why does Swift know it contains a boy but not a woman or girl? I could understand if it treated it as a single character and only recognized it containing itself, but the fact that it got one subcomponent and no others baffles me.
This does not change if I use something like "π©".characters.first!
.
Even more confounding is this:
let manual = "\u{1F469}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}"
Array(manual.characters) // ["π©β", "π©β", "π§β", "π¦"]
Even though I placed the ZWJs in there, they arenβt reflected in the character array. What followed was a little telling:
manual.contains("π©") // false
manual.contains("π§") // false
manual.contains("π¦") // true
So I get the same behavior with the character array⦠which is supremely annoying, since I know what the array looks like.
This also does not change if I use something like "π©".characters.first!
.