#import "ApiService.h"
@implementation ApiService
static ApiService *sharedInstance = nil;
+ (ApiService *)sharedInstance
{
if (sharedInstance == nil)
{
sharedInstance = [[self alloc]init];
}
return sharedInstance;
}
- (id)init
{
if (self = [super init])
{
}
return self;
}
@end
When I call +sharedInstance what does self refer to? How am I allowed to call init from a Class method?
selfis the class.Is the same as:
Or in your example:
This allows you to call class methods on
selffrom class methods. And it allows you to call them on the child class when you have inheritance, as class methods are inherited too.