Most of the other answers cover everything in a very detailed and accurate manner but I want to highlight some of the practices that I liked to preach when it comes to singleton classes.
I used to create a singleton and then all the public methods in the class were static. These static methods called the then call the replica instance methods using the private sharedInstance
As its a singleton all my method calls are going to be using shared instance ONLY so why specify it again and again.
class FGSingleton {
private static let sharedInstance = FGSingleton()
private var gameScore: Int = 0
// METHODS
private init() {
println(__FUNCTION__)
}
class func displayGameScore() {
println("\(__FUNCTION__) \(self.sharedInstance.gameScore)")
}
class func incrementGameScore(scoreInc: Int) {
self.sharedInstance.gameScore += scoreInc
}
}
and call will be simply
FGSingleton.incrementGameScore(5)
FGSingleton.displayGameScore()
UPDATE Just for a variation if you need to initialize some member variables in your singleton. You can do something like :
public static let sharedInstance: FGSingleton = {
let objBirthDate: NSDate = NSDate()
return FGSingleton(date: objBirthDate)
}()
required private init(data: NSDate){...}