In general, Swift really knows how to count graphemes as clusters as a single character. For example, if I want to make a Lebanese flag, I can combine two Unicode characters
- U + 1F1F1 LETTER OF THE SIGNAL OF THE REGIONAL INDICATOR L
- U + 1F1E7 SAMPLE SYMBOLS REGIONAL INDICATOR B
and, as expected, this is one character in Swift:
let s = "\u{1f1f1}\u{1f1e7}"
assert(s.characters.count == 1)
assert(s.utf16.count == 4)
assert(s.utf8.count == 8)
However, let me say that I want to make a Bicyclist emoji from Fitzpatrick Type-5. If i combine
- U + 1F6B4 BICYCLIST
- U + 1F3FE EMOJI MODIFIER FITZPATRICK TYPE-5
Swift considers this combination to be two characters!
let s = "\u{1f6b4}\u{1f3fe}"
assert(s.characters.count == 2)
assert(s.utf16.count == 4)
assert(s.utf8.count == 8)
Why are these two characters instead of one?
To show why I expect this to be 1, note that this cluster is actually interpreted as a valid emoji:
