I am learning about Singleton pattern in swift and efficient way to create a Singleton class and found out the best way to create as below.
class SingletonClass{
static let sharedInstance = SingletonClass()
}
Since i have use the let
statement it is read only property and has to be thread safe so there is no need of dispatch_once() as of Objective C.And static
is used to make the sharedInstance
variable as a class
variable i guess.
But how does this guarantee there is only one instance created throughout the application?is there a small thing i am missing?