Created
May 9, 2019 01:34
-
-
Save jboullianne/b2dcb82316b591a37b6ee69b0cd5a32f to your computer and use it in GitHub Desktop.
Singleton Design Pattern in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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