Get Description of Emoji Character

后端 未结 4 1221
野性不改
野性不改 2020-12-03 11:23

Each Emoji has a description that you can see in Mac OS\'s ⌃⌘Space special character picker. There\'s a list of them here. Is there a way for me to query for th

相关标签:
4条回答
  • 2020-12-03 11:26

    Swift 3 version of Eric Aya's answer:

    let s = "This is a                                                                     
    0 讨论(0)
  • 2020-12-03 11:33

    The Core Foundation function CFStringTransform() has transformations that determine the Unicode standard name for special characters. Example:

    let c : Character = "                                                                    
    0 讨论(0)
  • 2020-12-03 11:47

    Martin R's answer using Core Foundation's CFStringTransform() still works, but the key feature actually comes from kCFStringTransformToUnicodeName, and in Swift 2 we can use it simply like this, by bridging with NSString and calling stringByApplyingTransform:

    let c: Character = "                                                                    
    0 讨论(0)
  • 2020-12-03 11:47

    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 = "                                                                    
    0 讨论(0)
提交回复
热议问题