Skip to content

Instantly share code, notes, and snippets.

@xuyunan
Created March 21, 2013 09:13
Show Gist options
  • Save xuyunan/5211725 to your computer and use it in GitHub Desktop.
Save xuyunan/5211725 to your computer and use it in GitHub Desktop.
创建单例
static dispatch_once_t predicate;
+ (id)sharedUser
{
static id shareUser = nil;
dispatch_once(&predicate, ^{
shareUser = [[super allocWithZone:NULL] init];
});
return shareUser;
}
+ (id)allocWithZone:(NSZone *)zone
{
return [self sharedUser];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment