Quantcast
Channel: iOS-Blog » Tutorials
Viewing all articles
Browse latest Browse all 18

Quick tip: dispatch_once singleton model in Swift

$
0
0
From my short experience with iOS8 Swift there are three approaches to implement the Singleton pattern that support lazy initialisation and thread safety. Global constant Nested struct dispatch_once Download the Source Files for example These approaches might change or become redundant as the language matures. Global constant 1234567private let _SingletonSharedInstance = Singleton() class Singleton  {     class var sharedInstance : Singleton {         return _SingletonSharedInstance     } } We use a global constant because class ...

Viewing all articles
Browse latest Browse all 18

Trending Articles