1@interface RootObject
2+ (instancetype)alloc;
3
4- (instancetype)init;
5@end
6
7@interface BaseClass : RootObject
8+ (instancetype)sharedInstance;
9
10- (instancetype)initWithFoo:(int)foo;
11@end
12
13static BaseClass *sharedInstance = (void *)0;
14static int counter = 0;
15
16@implementation BaseClass
17+ (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@end
34
35