dispatch_once 單例設計模式

//單例模式
#import "MySingleton.h"
@implementation MySingleton
- (instancetype) sharedInstance{
    static MySingleton *SharedInstance = nil; 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{
            SharedInstance = [MySingleton new];
        });
    return SharedInstance; 
}
@end
相關文章
相關標籤/搜索