Skip to content

iOS: The singleton pattern #3

Open
@v5tech

Description

@v5tech

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;
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions