下面我们利用GCD来新建一个单例类
#import <Foundation/Foundation.h> @interface MZUserApplication : NSObject +(instancetype)shareInstance; - (BOOL)isAuthorized; @end #import "MZUserApplication.h" static id _instance; @implementation MZUserApplication +(instancetype)allocWithZone:(struct _NSZone *)zone{ static dispatch_once_t onceToken; dispatch_once(&onceToken,^{ _instance = [super allocWithZone:zone]; }); return _instance; } +(instancetype)shareInstance{ static dispatch_once_t onceToken; dispatch_once(&onceToken,^{ _instance = [[self alloc] init]; }); return _instance; } - (id)copyWithZone:(NSZone *)zone{ return _instance; } - (id)mutableCopyWithZone:(NSZone *)zone { return _instance; } -(BOOL)isAuthorized{ return [[NSUserDefaults standardUserDefaults]objectForKey:@"isLogin"]; } @end