Permalink
Browse files

gcm style sigleton

  • Loading branch information...
1 parent c4b68a0 commit 6a9e0d99feeb1e4851aaede665eff86e149d965d @scutdavy committed Aug 30, 2013
Showing with 6 additions and 3 deletions.
  1. +6 −3 objc/Nu.m
View
@@ -489,9 +489,10 @@ + (NuParser *) parser{
+ (NuParser *) sharedParser{
static NuParser *sharedParser = nil;
- if (!sharedParser) {
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
sharedParser = [[NuParser alloc] init];
- }
+ });
return sharedParser;
}
@@ -5929,8 +5930,10 @@ @implementation NuSelectorCache
+ (NuSelectorCache *) sharedSelectorCache{
static NuSelectorCache *sharedCache = nil;
- if (!sharedCache)
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
sharedCache = [[self alloc] init];
+ });
return sharedCache;
}

0 comments on commit 6a9e0d9

Please sign in to comment.