在网上看了很多方案,都是判断unicode值的范围,但是个人使用下来总有漏掉的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
}
}
查阅了官方文档后,使用如下方法不会有漏掉emoji的情况:
func isHaveEmjoy() -> Bool {
for scalar in unicodeScalars {
let result = scalar.properties.isEmoji
if result && (scalar.value < 48 || scalar.value > 57) {
// 48 - 56 是数字 1 - 9
// 57 是数字 0
return true
}
continue
}
return false
}
网友评论