
In Swift, you can simply use a static type property, which is guaranteed to be lazily initialized only once, even when accessed across multiple threads simultaneously:
1 |
class Singleton { |
If you need to perform additional setup beyond initialization, you can assign the result of the invocation of a closure to the global constant:
1 |
class Singleton { |




近期评论