Last active
February 1, 2018 09:23
-
-
Save gonzalezreal/76e34eaef20ee74d19dd 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
According to the documentation, globals are lazily evaluated and thread safe. I wonder if this statement also applies to type properties.