Tutorial by Examples

GCD will guarantee that your singleton only gets instantiated once, even if called from multiple threads. Insert this into any class for a singleton instance called shared. + (instancetype)shared { // Variable that will point to the singleton instance. The `static` // modifier makes it ...
We can create Singleton class in such a way that developers are forced to used the shared instance (singleton object) instead of creating their own instances. @implementation MySingletonClass + (instancetype)sharedInstance { static MySingletonClass *_sharedInstance = nil; static dispa...
//MySingletonClass.h @interface MYSingletonClass : NSObject + (instancetype)sharedInstance; -(instancetype)init NS_UNAVAILABLE; -(instancetype)new NS_UNAVAILABLE; @end //MySingletonClass.m @implementation MySingletonClass + (instancetype)sharedInstance { static MySingleto...

Page 1 of 1