Singleton Class in Swift

Singleton is a common pattern that limits possibility to create multiple instances of a class.

It's very easy to make singleton in Swift:

public class Defaults {
    static let shared = Defaults()
    private init() {}
}

Usage:

class AppDelegate: UIResponder, UIApplicationDelegate {
    private let defaults = Defaults.shared
}