我想利用 swift 在变量名称中支持 unicode 字符这一事实,但我无法让它工作。我有一个 UIView
我在某个方向绘制的子类。我的计划是有一个这样的枚举:
enum ShapeDirection {
case ←
case →
case ↑
case ↓
case ↖
case ↗
case ↘
case ↙
}
我认为这是有效的,但我不断收到此错误:
Unary operand cannot be separated from its operand
我试着给ShapeDirection
类型( String
)并为每个案例分配值,但问题仍然相同。我还尝试用其中一个箭头作为名称来初始化一个独立变量,但我得到了同样的错误。这是否意味着编译器不支持这组特定的 unicode 字符?是否存在所有方向箭头的等价完整集?
编辑:
对于那些想知道什么是干净的代码、什么是可读的以及故事如何结束的人 - 我选择了北、南、东、西等简单案例,箭头作为 String
中的原始值。格式。
最佳答案
更新:它们在运算符中是允许的,但是 explicitly not in identifiers (the names of things) :
identifier-head → U+2070–U+20CF, U+2100–U+218F, [U+2190 and forward missing] U+2460–U+24FF, or U+2776–U+2793
所以这按预期工作,或者至少按设计工作。
这听起来像是一个错误。 All of these characters可用inside the following range of the Swift grammar :
operator-head → U+2190–U+23FF
...所以听起来您遇到了错误或没有将文件保存在例如UTF-8。
关于ios - 对变量名或枚举大小写使用 unicode 箭头字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32458260/