title: Singleton pattern in Swift 1.2
body: <p>I have previously used the following singleton pattern:</p>
  
  <pre><code>class Singleton {
      class var sharedInstance : Singleton {
          struct Static {
              static let instance : Singleton = Singleton()
          }
          return Static.instance
      }   
  }
  </code></pre>
  
  <p>When the new Xcode beta with Swift 1.2 was released I wanted to try out the new static class properties and methods. So I tried something similar to this:</p>
  
  <pre><code>class Singleton {
      static let sharedInstance : Singleton = Singleton()
  }
  </code></pre>
  
  <p>Looking at the debugger while using this it seems like a lot of nested instances of the singleton class are created by the class constant:</p>
  
  <p><img src="https://i.stack.imgur.com/03rFc.png" alt="Screenshot of debugger"></p>
  
  <p>But looking thru the allocations it seems that only one instance are created. I guess that means it's working correctly, but I'm not seeing the same behavior with the first pattern.</p>