Created
November 13, 2018 19:26
-
-
Save ankitthakur/e6650172a6b0ce1f1fb67d462fdcff1b to your computer and use it in GitHub Desktop.
Singleton Swift class
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
final class MyClass { | |
private init() {} | |
private static var _shared: MyClass? | |
public static var shared: MyClass { | |
get { | |
if _shared == nil { | |
DispatchQueue.global().sync(flags: .barrier) { | |
if _shared == nil { | |
_shared = MyClass() | |
} | |
} | |
} | |
return _shared! | |
} | |
} | |
func someFuntion() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment