Class variables not yet supported

Embedding a struct can work just fine as a workaround:

class SomeClass
{
  // class var classVariable: Int = 0
  // "Class variables not yet supported." Weird.

  // Workaround:
  private struct SubStruct { static var staticVariable: Int = 0 }

  class var workaroundClassVariable: Int
  {
    get { return SubStruct.staticVariable }
    set { SubStruct.staticVariable = newValue }
  }
}

The SomeClass.workaroundClassVariable computed type property can then be used as if it were a stored type property.

Leave a Comment