Everything I know about programming says that instance methods can call class methods, but class methods cannot call instance methods.
This post agrees... Call instance method from class method
Yet miraculously the class method sharedInstance
manages to call instance method init
. What am I missing ??
static iRpDatabase *sharedDatabase;
@implementation iRpDatabase
{
}
+(iRpDatabase*)sharedInstance
{
if(sharedDatabase == nil)
{
sharedDatabase = [[self alloc] init];
}
return sharedDatabase;
}
// this is an instance method, called from class method above.
-(id)init
{
if (self = [super init]) {
someInstanceVariable = XYZ;
[self someInstanceMethod];
}
return self;
}