I am trying to figure out the best implementation of a singleton this is the latest I got.
This is the .m file implementation, anything wrong with it:
#import "Foo.h"
static Foo *object = nil;
@implementation Foo
+ (Foo*)sharedObject {
return [[Foo alloc] init];
}
- (id)init {
static dispatch_once_t once;
dispatch_once(&once, ^{
object = [super init];
});
return object;
}
@end
and to use it I can do:
[Foo sharedObject]
or
[[Foo alloc] init]
And both will return the same object.