Skip to content

Instantly share code, notes, and snippets.

@vincent178
Created April 12, 2014 08:46
Show Gist options
  • Save vincent178/10525242 to your computer and use it in GitHub Desktop.
Save vincent178/10525242 to your computer and use it in GitHub Desktop.
singleton in objc
+ (instancetype)sharePreference {
static TFUserPreference *sharePreference = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharePreference = [[self alloc] init];
});
return sharePreference;
}
- (id)init {
self = [super init];
if (self) {
self.userDefaults = [NSUserDefaults standardUserDefaults];
}
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment