Skip to content

Instantly share code, notes, and snippets.

@marmelroy
Last active July 3, 2016 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marmelroy/15da0fa6f0936ed6b92392e9df07e235 to your computer and use it in GitHub Desktop.
Save marmelroy/15da0fa6f0936ed6b92392e9df07e235 to your computer and use it in GitHub Desktop.
// 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