How do I get the typeof method inside a class?

For singleton I often do it like this

+ (instancetype)sharedManager
{
    static id instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];
    });

    return instance;
}

      

But this static id instance = nil

one is not type-strict, so I want something like

static typeof(self) instance = nil

      

But self

here is an instance of the Singleton class, which is readonly. How can I infer the typeof from this class method?

+3


source to share





All Articles