With Swift 5, you can use one of the two following ways in order to get the description of an Emoji character.
#1. Using Unicode.Scalar.Properties
's name
property
Unicode.Scalar.Properties
has a name
property. name
has the following declaration:
var name: String? { get }
The published name of the scalar.
The Playground code sample below shows how to use name
in order to get the published name of a Unicode scalar:
let emoji: Character = ""
for scalar in emoji.unicodeScalars {
print(scalar.properties.name)
}
/*
prints: Optional("SMILING FACE WITH OPEN MOUTH AND SMILING EYES")
*/
#2. Using Unicode.Scalar.Properties
's nameAlias
property
Unicode.Scalar.Properties
also has a property called nameAlias
with the following declaration:
var nameAlias: String? { get }
The normative formal alias of the scalar. [...] The nameAlias
property is provided to issue corrections if a name was issued erroneously. For example, the name of U+FE18 is “PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRAKCET” (note that “BRACKET” is misspelled). The nameAlias
property then contains the corrected name.
The Playground sample codes below show the difference between name
and nameAlias
for U+FE18 Unicode scalar:
let emoji: Character = "\u{FE18}" // ︘
for scalar in emoji.unicodeScalars {
print(scalar.properties.name)
}
/*
prints:
Optional("PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRAKCET")
*/
let emoji: Character = "\u{FE18}" // ︘
for scalar in emoji.unicodeScalars {
print(scalar.properties.nameAlias)
}
/*
prints:
Optional("PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRACKET")
*/