-
-
Save arturdent/b4eaae4242ad37bb511c to your computer and use it in GitHub Desktop.
A naive? attempt to create a Singleton 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 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