brintos

brintos / llvm-project-archived public Read only

0
0
Text · 576 B · 282baff Raw
35 lines · plain
1@interface RootObject2+ (instancetype)alloc;3 4- (instancetype)init;5@end6 7@interface BaseClass : RootObject8+ (instancetype)sharedInstance;9 10- (instancetype)initWithFoo:(int)foo;11@end12 13static BaseClass *sharedInstance = (void *)0;14static int counter = 0;15 16@implementation BaseClass17+ (instancetype)sharedInstance {18  if (sharedInstance) {19    return sharedInstance;20  }21  sharedInstance = [[BaseClass alloc] initWithFoo:3];22  return sharedInstance;23}24 25 26- (instancetype)initWithFoo:(int)foo {27  self = [super init];28  if (self) {29    counter += foo;30  }31  return self;32}33@end34 35