In Objective-C, this worked well for a Singleton in Interface Builder
static Universe *instance;
+ (Universe *)instance {
return instance;
}
+ (id)hiddenAlloc {
return [super alloc];
}
+ (id)alloc {
return [self instance];
}
+ (void)initialize {
static BOOL initialized = NO;
if (!initialized) {
initialized = YES;
instance = [[Universe hiddenAlloc] init];
}
}
and due to the overwriting of the alloc, IB would pick up the only instance of Universe
Is this possible in Swift? [I've gotten stuck with my solution, which is here on Github.]