Last active
July 17, 2017 12:54
-
-
Save bleft/336337e43cbca32c6819 to your computer and use it in GitHub Desktop.
swift singleton
This file contains hidden or 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
class SingletonClass { | |
static let shared = SingletonClass() | |
// mark init as private to prevent from calling it directly | |
private init(){ | |
// set your default properties | |
} | |
class var shared: SingletonClass { | |
if _sharedSingletonInstance == nil { | |
_sharedSingletonInstance = SingletonClass() | |
} | |
return _sharedSingletonInstance | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
get it with:
let shared = SingletonClass.shared