Skip to content

Instantly share code, notes, and snippets.

Last active February 1, 2018 09:23
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gonzalezreal/76e34eaef20ee74d19dd 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
Copy link

According to the documentation, globals are lazily evaluated and thread safe. I wonder if this statement also applies to type properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment