定义:单例模式可以保证系统中存在某个类的唯一实例,用于数据共享
类型:对象创建
类图:
应用场景
#import <Foundation/Foundation.h>
@interface Singleton : NSObject
@end
#import "Singleton.h" @implementation Singleton + (instancetype)shareInstance{ static Singleton *singleton = nil; dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ singleton = [[self class] alloc]; }); return singleton; } @end