.h文件中
#import <Foundation/Foundation.h>
@interface WMSingleton : NSObject
+(instancetype)sharedInstance;
@end
.m文件中
#import "WMSingleton.h"
@implementation WMSingleton
static WMSingleton * _instance = nil;
+(instancetype)sharedInstance {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[self alloc]init];
});
return _instance;
}
@end
网友评论