Yog*_*esh 13 xcode ios swift ios8
我正在使用Xcode游乐场在Swift中使用emojis来处理一些简单的iOS8应用程序.为此,我想创建类似于unicode/emoji地图/描述的东西.
为了做到这一点,我需要一个循环,允许我打印出一个表情符号列表.我正在考虑这些问题
for i in 0x1F601 - 0x1F64F {
var hex = String(format:"%2X", i)
println("\u{\(hex)}") //Is there another way to create UTF8 string corresponding to emoji
}
Run Code Online (Sandbox Code Playgroud)
但是println()会抛出错误
Expected '}'in \u{...} escape sequence.
Run Code Online (Sandbox Code Playgroud)
有一种简单的方法可以做到这一点,我错过了吗?
据我所知,并非所有参赛作品都与表情符号相对应.此外,我可以创建一个查询表,参考http://apps.timwhitlock.info/emoji/tables/unicode,但我想要一个懒惰/简单的方法来实现相同.
Mik*_*e S 43
你也可以遍历这些十六进制值有Range
:0x1F601...0x1F64F
,然后创建String
使用A S UnicodeScalar
:
for i in 0x1F601...0x1F64F {
var c = String(UnicodeScalar(i))
print(c)
}
Run Code Online (Sandbox Code Playgroud)
输出:
如果你想要所有的表情符号,只需在一系列范围上添加另一个循环:
// NOTE: These ranges are still just a subset of all the emoji characters;
// they seem to be all over the place...
let emojiRanges = [
0x1F601...0x1F64F,
0x2702...0x27B0,
0x1F680...0x1F6C0,
0x1F170...0x1F251
]
for range in emojiRanges {
for i in range {
var c = String(UnicodeScalar(i))
print(c)
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11861 次 |
最近记录: |