Earlier, I used the following singleton pattern:
class Singleton { class var sharedInstance : Singleton { struct Static { static let instance : Singleton = Singleton() } return Static.instance } }
When the new beta version of Xcode with Swift 1.2 was released, I wanted to try new properties and methods of a static class. So I tried something similar to this:
class Singleton { static let sharedInstance : Singleton = Singleton() }
Looking at the debugger when using this, it seems that many nested instances of the same singlet class are created by the class constant:

But, looking through the distribution, it seems that only one instance is created. I assume this means that it works correctly, but I do not see the same behavior with the first pattern.
swift
Kristoffer Johansson
source share