Skip to content

Instantly share code, notes, and snippets.

@bleft
Last active July 17, 2017 12:54
Show Gist options
  • Save bleft/336337e43cbca32c6819 to your computer and use it in GitHub Desktop.
Save bleft/336337e43cbca32c6819 to your computer and use it in GitHub Desktop.
swift singleton
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
}
}
@bleft
Copy link
Author

bleft commented Jan 26, 2015

get it with:
let shared = SingletonClass.shared

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment