title: Singleton in one line on Swift 2.0
body: <p>Please help me with Swift,
  I need singleton with can inheritance.
  I can do like this</p>
  
  <pre><code>class A {
      var defaultPort: Int
      required init() {
          self.defaultPort = 404
      }
      class var defaultClient: A {
          struct Static {
              static var onceToken: dispatch_once_t = 0
              static var instance: A? = nil
          }
          dispatch_once(&amp;Static.onceToken) {
              Static.instance = self.init()
          }
          return Static.instance!
      }
  }
  </code></pre>
  
  <p>but in swift 2.0 we can do like this</p>
  
  <pre><code>static let defaultClient = A() //self.init() 
  </code></pre>
  
  <p>but it creates an instance of the class A any way.
  How i can use like this <strong>self.init()</strong> </p>
  
  <pre><code>static let defaultClient = self.init()
  </code></pre>
  
  <p>in order to be able to inherit</p>
  
  <p><strong>UPD</strong>
  best way for now</p>
  
  <pre><code>class A {
      class func defaultClient() -&gt; Self {
          struct Static {
              static var onceToken: dispatch_once_t = 0
              static var instance: A? = nil
          }
          dispatch_once(&amp;Static.onceToken) {
              Static.instance = self.init()
          }
          return instance(Static.instance, asType: self)
      }
  }
  </code></pre>
  
  <p>here we need helper as</p>
  
  <pre><code>func instance&lt;T&gt;(instance: Any, asType type: T.Type) -&gt; T {
      let reurnValue = instance as! T
      return reurnValue
  }
  </code></pre>
  
  <p>because another way cast A to Self not exist, for now.</p>
  
  <blockquote>
    <p>p.s. crazy swift way! 
    why i can not do <strong>instance as! Self</strong></p>
  </blockquote>