OC单例
#import "NetworkTools.h"
@implementation NetworkTools
+ (instancetype)sharedTools {
static NetworkTools *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[NetworkTools alloc] init];
});
return instance;
}
@end
swift单例
import UIKit
class SoundTools: NSObject {
//let 不可变 同样是线程安全的
static let tools: SoundTools = SoundTools()
}