I was looking at modern patterns of Objective-C to create singletons after the introduction of instance
from: Create singleton using GCD's dispatch_once in Objective C
+ (instancetype)sharedInstance
{
static dispatch_once_t once;
static id sharedInstance;
dispatch_once(&once, ^
{
sharedInstance = [self new];
});
return sharedInstance;
}
And I was wondering why not use [MyFunnyClass new] as below?
@implementation MyFunnyClass
+ (instancetype)sharedInstance
{
static dispatch_once_t once;
static id sharedInstance;
dispatch_once(&once, ^
{
sharedInstance = [MyFunnyClass new];
});
return sharedInstance;
}
Or if it's the same?
(Ref: http://nshipster.com/instancetype/)
Edit: the answers given at Why use [ClassName alloc] instead of [[self class] alloc]? are not related to this question