Created
February 14, 2015 23:15
-
-
Save ajjames/208deef4e0c9636b77cf 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 mySingletonClass | |
{ | |
class var default: mySingletonClass | |
{ | |
struct Static | |
{ | |
static var instance: mySingletonClass? | |
static var token: dispatch_once_t = 0 | |
} | |
dispatch_once(&Static.token) { | |
Static.instance = mySingletonClass() | |
} | |
return Static.instance! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment