Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: The singleton pattern #3

Open
v5tech opened this issue Sep 16, 2014 · 0 comments
Open

iOS: The singleton pattern #3

v5tech opened this issue Sep 16, 2014 · 0 comments

Comments

@v5tech
Copy link
Owner

v5tech commented Sep 16, 2014

person.h

#import <Foundation/Foundation.h>

@interface Person : NSObject 

+ (id)sharedInstance;

@end

person.m

+ (id)sharedInstance {
    static Person *theSharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        theSharedInstance = [[self alloc] init];
    });
    return theSharedInstance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant