小编Sam*_* S.的帖子

Swift:用户输入的十六进制字符串到unicode字符

我在将用户输入的十六进制字符串(即“1F436”)转换为我可以使用的 unicode 字符时遇到问题。

通过阅读 Swift 文档,我学习了如何使用 'print(\u{1F436})' 打印 unicode 字符,以及如何使用 for-in 循环计算出字符串中 unicode 字符的十进制值。

但是,如何从包含十六进制数字的字符串创建 unicode 字符变量呢?

string unicode swift

4
推荐指数
1
解决办法
875
查看次数

Swift:切换声明的通过行为

目前我有这个:

let somePoint = (1, 0)

switch somePoint {
case (0,0):
    print("origin") // does not print
    fallthrough
case (_, 0):
    print("y-axis") // prints y-axis. this makes sense
    fallthrough
case(0, _):
    print("x-axis") // prints x-axis (because of fallthrough? this should not print)
    fallthrough
case(-2...2, -2...2):
    print("in 5x5 box about the origin") // this prints and makes sense
default:
    print("somewhere else") // does not print
}
Run Code Online (Sandbox Code Playgroud)

我的这个switch语句的目标是让每个case打印如果它是真的而不是只有第一个匹配print的case.我以为我可以通过这个演绎声明来做到这一点.但是,这让我怀疑它是如何工作的.即使案例不匹配,为什么fallthrough会自动打印下一个案例?我怎么能按照我想要的方式使这个switch语句工作?

switch-statement swift

2
推荐指数
1
解决办法
3001
查看次数

标签 统计

swift ×2

string ×1

switch-statement ×1

unicode ×1