Skip to content

Instantly share code, notes, and snippets.

@arturdent
Forked from gonzalezreal/Singleton.swift
Created February 2, 2016 00:46
Show Gist options
  • Save arturdent/b4eaae4242ad37bb511c to your computer and use it in GitHub Desktop.
Save arturdent/b4eaae4242ad37bb511c to your computer and use it in GitHub Desktop.
A naive? attempt to create a Singleton in Swift
class FileManager {
struct StaticInstance {
static var instance = FileManager()
}
class var defaultManager : FileManager {
return StaticInstance.instance
}
}
var mgr1 = FileManager.defaultManager
var mgr2 = FileManager.defaultManager
let mustBeTrue = mgr1 === mgr2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment