Last active
July 3, 2016 09:56
-
-
Save marmelroy/15da0fa6f0936ed6b92392e9df07e235 to your computer and use it in GitHub Desktop.
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
// Examples of dispatch_once replacements with global or static constants and variables. | |
// In all three, the initialiser is called only once. | |
// Static properties (useful for singletons). | |
class Object { | |
static let sharedInstance = Object() | |
} | |
// Global constant. | |
let constant = Object() | |
// Global variable. | |
var variable: Object = { | |
let variable = Object() | |
variable.doSomething() | |
return variable | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment