如何在类作用域中声明静态常量?例如:
class let Constant: Double = 3.1415926
// I know that in class we use class modifier instead of static.
从Swift 1.2开始,Swift支持类的静态类型属性:
class MyClass {
static let pi = 3.1415926
}
如果您需要在子类中重写的类变量,则需要使用计算类属性:class MyClass {
class var pi: Double { return 3.1415926 }
}
class IndianaClass : MyClass {
override class var pi: Double { return 4 / (5 / 4) }
}
enums
中才是这样... - Sumner Evans