Getting class when instantiating a singleton

Alex Zavatone

I did this a few years ago but can’t find my sample and figured I’d ask the brain trust here.

In iOS, when I’m making an Objective-C singleton, in the public method that returns the instanceType, we need to put the class name.  Is there a way to do this dynamically instead of entering the class name all the time?  

For example, where I have “DataSingleton" below, can’t we get the name of class instance without having to enter the class name?  This would be so much nicer and time saving.

@implementation CrewActionsDataSingleton

+ (instancetype)sharedInstance
   static DataSingleton *instance;
   static dispatch_once_t onceToken;

   dispatch_once(&onceToken, ^{
       instance = [[self alloc] init];
   return instance;

Thanks in advance.

Alex Zavatone

Join to automatically receive all group messages.