swiftly的单例比OC的更加简单!
class MySingletonClass {
static let sharedInstance = MySingletonClass()
private init() {
}
}
Oc中的单例:
@implementation MySingletonClass
+(id)sharedInstance {
static MySingletonClass *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}