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
ios objective-c singleton typeof


source to share


No one has answered this question yet

Check out similar questions:

814
Creating a singlet in Python
158
In Objective-C, why should I check if self = [super init] is not null?
13
instancetype vs class name for singleton?
4
What does the Singleton example in Apple's documentation actually do?
2
What are the implications of ARC for using "init" in non-initializer names for single classes
2
How do I get the class that is defined by the method, and not the instance that is called by the method?
0
I am trying to get alloc init and nil to work inside a method in ObjC
0
Accessing sharedInstance from a class method
0
What happens if the init method of one class is called before the + sharedInstance method ..?
-6
How do I use general preferences in xcode using Object-C?



All Articles
Loading...
X
Show
Funny
Dev
Pics