Skip to content

Instantly share code, notes, and snippets.

@Ziewvater
Created March 27, 2015 00:25
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Ziewvater/998b5806b0d12e4cf35b to your computer and use it in GitHub Desktop.
Save Ziewvater/998b5806b0d12e4cf35b to your computer and use it in GitHub Desktop.
Determining if swift string contains emoji character
func containsEmoji(text: String) -> Bool {
var containsEmoji = false
for scalar in text.unicodeScalars {
switch scalar.value {
case 0x1F600...0x1F64F:
// Emoticons
containsEmoji = true
case 0x1F300...0x1F5FF:
// Misc Symbols and Pictographs
containsEmoji = true
case 0x1F680...0x1F6FF:
// Transport and Map
containsEmoji = true
case 0x2600...0x26FF:
// Misc symbols, not all emoji
containsEmoji = true
case 0x2700...0x27BF:
// Dingbats, not all emoji
containsEmoji = true
default: ()
}
}
return containsEmoji
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment