Ensure a class has only one instance, and provide a global point of access to it.
Source: wikipedia.org
final class Singleton {
static let sharedInstance = Singleton()
private init() {
// Private initialization to ensure just one instance is created.
}
}
let singleton = Singleton.sharedInstance
object Singleton {
init {
println("Initializing with object: $this")
}
fun doSomething() = println("Do something with object: $this")
}
Singleton.doSomething()