Why emoji characters like 👩👩👧👦 behave strangely in Swift strings?
Hello everyone! I'm writing an iOS app that processes texts with emojis. And I encountered strange behavior in Swift when working with multi-component emojis, especially families and flags.
For example, I have a string `let family = "👩👩👧👦"`. I expect `family.count` to return 1 (since it's one emoji!), but instead I get 7. And if I try to get the first character via `family.first`, it returns not the whole emoji, but some strange character.
Here's the code that confused me:
```swift
let family = "👩👩👧👦"
print(family.count) // 7
print(family.utf8.count) // 25
print(family.utf16.count) // 11
print(family.unicodeScalars.count) // 7
print(family.first) // Optional("👩")
```
I expected count to be 1 and first to return the whole emoji. Why does Swift count these characters differently? How to properly work with such emojis in Swift? I'm especially interested in how to safely truncate strings containing such composite emojis without breaking them apart.