The first time I learned how to Implement Singleton Pattern in Swift is in this Book Pro Design Patterns in Swift
.
The way I started implementing the Singleton Pattern is in the example below:
class Singleton {
class var sharedInstance: Singleton {
struct Wrapper {
static let singleton = Singleton()
}
return Wrapper.singleton
}
private init() {
}
}
But then I found this implementation while reading about Cocoa Design Patterns
class Singleton {
static let sharedInstance = Singleton()
private init() {
}
}
So my question is, what's the difference between the two implementations ?
Aucun commentaire:
Enregistrer un commentaire