I am developing keyboard extension for iPhone. There is an emoji screen smilar to Apples own emoji keyboard that shows some 800 emoji characters in UICollectionView
Many emojis are represented by sequences that contain more than one unicode scalar. Matthew's answer works well with basic emojis but it returns only first scalar from the sequences of emojis like country flags.
The code below will get full sequences and create a string that matches gemoji exported file names.
Some simple smiley emojis also have the fe0f selector. But gemoji doesn't add this selector to file names on exporting, so it should be removed.
func emojiToHex(_ emoji: String) -> String
{
var name = ""
for item in emoji.unicodeScalars {
name += String(item.value, radix: 16, uppercase: false)
if item != emoji.unicodeScalars.last {
name += "-"
}
}
name = name.replacingOccurrences(of: "-fe0f", with: "")
return name
}