1. OC 单例
+ (NetworkTool *)sharedNetworkTool {
static id instace;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instace = [[self alloc] init];
});
return instace;
}
2. Swift 单例
private static let instance = NetworkTool()
class func sharedNetwork() -> NetworkTool{
return instance
}
原文:http://www.cnblogs.com/yangzhifan/p/4529410.html