Objective-c 实现单例设计模式

#import <Foundation/Foundation.h>


@interface Singleton : NSObject

@property (nonatomic, strong) NSString *singletonData;

+ (Singleton *)sharedManager;

@end




#import "Singleton.h"


@implementation Singleton

@synthesize singletonData = _singletonData;

static Singleton *sharedManager = nil;

+ (Singleton *)sharedManager

{

static dispatch_once_t once;

dispatch_once(&once, ^{

    sharedManager = [[self alloc] init];

});

return sharedManager;

}


@end


你可能感兴趣的:(Objective-c 实现单例设计模式)