+(MyClass *)singleton {
static dispatch_once_t pred;
static MyClass *shared = nil;
dispatch_once(&pred, ^{
shared = [[MyClass alloc] init];
});
return shared;
}
dispatch_once() function is indeed mentioned in Mac Developer Library that is useful in implementing singletons or global data.
Hope you found this helpful.


0 comments:
Post a Comment