title: Singleton Class returning its property nil in swift?
body: <p>I am trying to learn Singleton Class in Playground but dont know how to get its only one instance.Why is this singleton class returning nil while accessing its property?It would be great if someone would explain me why do i need  this Static class?</p>
  
  <pre><code>class SingletonC {
      var a:String?
  
      class var sharedInstance: SingletonC {
  
          struct Static {
              static var onceToken: dispatch_once_t = 0
              static var instance: SingletonC? = nil
          }
  
          dispatch_once(&amp;Static.onceToken) {
              Static.instance = SingletonC()
          }
  
          return Static.instance!
      }
  }
  var ab = SingletonC()
  
  ab.a = "fdsfds"
  
  SingletonC.sharedInstance.a //prints nil
  </code></pre>
  
  <p><strong>UPDATED:</strong>
  After experimenting sometimes i got the value</p>
  
  <pre><code>SingletonC.sharedInstance.a = "Hello"
  SingletonC.sharedInstance.a
  </code></pre>
  
  <p><em>But can i obtain this by creating a object of <code>SingletonC</code>for the first time?What is the way to use Singleton class?</em></p>