dispatch_once is synchronous and its saying "perform something once and only once".It replaces the following:
+ (MyClass *)sharedInstance {
static MyClass *sharedInstance;
@synchronized(self) {
if (sharedInstance == nil) {
sharedInstance = [[MyClass alloc] init];
}
}
return sharedInstance;
}
Advantage of dispatch_once is its faster.
No comments:
Post a Comment