Last active
August 29, 2015 14:02
-
-
Save MrCloud/d04fb37b530b9c040840 to your computer and use it in GitHub Desktop.
An Xcode Snippet for Singleton implementation 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
class <#ClassName#> { | |
class func sharedInstance() -> <#ClassName#> { | |
struct Static<#ClassName#> { | |
static let sharedInstance = <#ClassName#>() | |
} | |
return <#ClassName#>.sharedInstance | |
} | |
} | |
/* You might ask why there is no GCD related calls here with the obvious dispatch_once/token pair here. | |
Well in fact Swift does this for you under the hood, yes: Global and static properties are already dispatch_once'd | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Swift FTW !