Category: Uncategorized

Singletons in Swift

If you come from the Objective-C world, you’re probably familiar with the singleton pattern. @implementation MyClass + (id)sharedInstance { static MyClass *__instance = nil static dispatch_once_t token; dispatch_once(&token, ^{ __instance = [[MyClass alloc] init]; }); return __instance; } @end Okay, here’s how you declare a singleton in Swift: class MyClass { static let sharedInstance =…

Read the full article

Subscribe

Subscribe to get my updates on new products, tutorials, apps, and content you may be interested in. I write about software development — mostly iOS and Elixir/Phoenix. If you like what I produce, subscribing is the best way to support what I do. In case you didn’t know: I’m about to publish a book, check…

Read the full article