Re: Getting class when instantiating a singleton


Alex Zavatone
 

On Aug 30, 2017, at 3:54 PM, Ben Kennedy <ben@...> wrote:


On 30 Aug 2017, at 1:37 pm, Alex Zavatone <zav@...> wrote:

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?
Why is this necessary? Apologies if I'm missing something obvious, but what's wrong with literally using DataSingleton (in your example)?

Even if the method is called on a subclass it should still work as desired because you're calling [self alloc], not [DataSingleton alloc].

-ben
It makes the code copy/paste-able. No dependency on the name of class you are adding it to.

Join cocoa@apple-dev.groups.io to automatically receive all group messages.