Tel Tel - 3 months ago 10
Swift Question

How to replace emoji characters with their descriptions in a Swift string

I'm looking for a way to replace emoji characters with their description in a Swift string.

Example:


Input
"This is my string

Tel Tel
Answer

Here is a complete implementation.

It avoids to convert to description also the non-emoji characters (e.g. it avoids to convert to {LEFT DOUBLE QUOTATION MARK}). To accomplish this, it uses an extension based on this answer by Arnold that returns true or false whether a string contains an emoji.

The other part of the code is based on this answer by MartinR and the answer and comments to this answer by luk2302.

var str = "Hello World