Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jboullianne/b2dcb82316b591a37b6ee69b0cd5a32f to your computer and use it in GitHub Desktop.
Save jboullianne/b2dcb82316b591a37b6ee69b0cd5a32f to your computer and use it in GitHub Desktop.
Singleton Design Pattern in Swift
// Singleton Design Pattern Example
// Author: Jean-Marc Boullianne
class Singleton {
static let instance = Singleton()
private init() {
// Initialize class variable here
}
func shared() -> Singleton {
return instance
}
}
// Example for getting an instance of the class in code...
// ....
var singletonInstance = Singleton.shared()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment