Created
March 27, 2015 00:25
-
-
Save Ziewvater/998b5806b0d12e4cf35b to your computer and use it in GitHub Desktop.
Determining if swift string contains emoji character
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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