Does it have static class level variables fast?

How to declare a static constant in a class? such as

class let Constant: Double = 3.1415926 // I know that in class we use class modifier instead of static. 
+43
static class swift
Nov 07 '14 at 15:02
source share
1 answer

Swift supports static type properties, including for classes starting with Swift 1.2:

 class MyClass { static let pi = 3.1415926 } 

If you need to have a class variable that is overridden in a subclass, you need to use the property of the computed class:

 class MyClass { class var pi: Double { return 3.1415926 } } class IndianaClass : MyClass { override class var pi: Double { return 4 / (5 / 4) } } 
+107
Nov 07 '14 at 15:17
source share



All Articles