[objective-c]シングルトンクラス
シングルトンクラス
DataBaseManager.h
#import <Foundation/Foundation.h> #import "EGODatabase.h" @interface DataBaseManager : NSObject{ } + (DataBaseManager*)sharedInstance; @end
DataBaseManager.m
#import "DataBaseManager.h" @implementation DataBaseManager + (DataBaseManager*)sharedInstance { static DataBaseManager* _instance; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _instance = [[DataBaseManager alloc]initSharedInstance]; }); return _instance; } - (id)initSharedInstance { self = [super init]; if (self) { //初期化 } return self; } @end
使うとき
DataBaseManager*dbm=[DataBaseManager sharedInstance];