I am creating a singleton class in obj c with the following Dispatch once block,
in ClassName.m
+ (instancetype)sharedInstance
{
static ClassName*objClassName = nil;
static dispatch_once_t onceToken = 0;
dispatch_once(&onceToken, ^{
objClassName = [[ClassName alloc]init];
});
return objClassName;
}
and I am using the following code in ClassName.h
to not allow using alloc and init
- (id)init __attribute__((unavailable("You cannot init this class directly. Use sharedInstance to get the singleton Instance")));
+ (id)alloc __attribute__((unavailable("You cannot alloc this class directly. Use sharedInstance to get the singleton Instance")));
+ (id)new __attribute__((unavailable("You cannot use new this class directly. Use sharedInstance to get the singleton Instance")));
but it is not allowing my singleton method to use alloc init , please let me the where am I going wrong,