在網(wǎng)上看了很多方案嬉橙,都是判斷unicode值的范圍寒屯,但是個(gè)人使用下來(lái)總有漏掉的emoji
for scalar in unicodeScalars {
switch scalar.value {
case 0x1F600...0x1F64F, // Emoticons
0x1F300...0x1F5FF, // Misc Symbols and Pictographs
0x1F680...0x1F6FF, // Transport and Map
0x1F1E6...0x1F1FF, // Regional country flags
0x2600...0x26FF, // Misc symbols
0x2700...0x27BF, // Dingbats
0xE0020...0xE007F, // Tags
0xFE00...0xFE0F, // Variation Selectors
0x1F900...0x1F9FF, // Supplemental Symbols and Pictographs
127000...127600, // Various asian characters
65024...65039, // Variation selector
9100...9300, // Misc items
8400...8447: // Combining Diacritical Marks for Symbols
return true
default:
continue
}
}
查閱了官方文檔后罕偎,使用如下方法不會(huì)有漏掉emoji的情況:
func isHaveEmjoy() -> Bool {
for scalar in unicodeScalars {
let result = scalar.properties.isEmoji
if result && (scalar.value < 48 || scalar.value > 57) {
// 48 - 56 是數(shù)字 1 - 9
// 57 是數(shù)字 0
return true
}
continue
}
return false
}