Skip to content

Instantly share code, notes, and snippets.

@hassi32
Created November 29, 2017 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hassi32/5ebdfc7ab0d95af7680f5489f6fcba7f to your computer and use it in GitHub Desktop.
Save hassi32/5ebdfc7ab0d95af7680f5489f6fcba7f to your computer and use it in GitHub Desktop.
encode emoji in Swift
func encode(_ s: String) -> String {
let data = s.data(using: .nonLossyASCII, allowLossyConversion: true)!
return String(data: data, encoding: .utf8)!
}
let emoji = "👪"
encode(emoji) // \ud83d\udc6a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment