iOS单例

+(SingleObject *)sharedInstance{
    static SingleObject * ourSharedInstance = nil;
    if (ourSharedInstance)
    {
        static dispatch_once once ;
        dispatch_once(&once,^{
            // ourSharedInstance = [[SingleObject alloc] init];
            // 使用[self class]兼容子类
            ourSharedInstance = [[[self class] alloc] init];
        });
    }
    return ourSharedInstance;
}

你可能感兴趣的:(iOS单例)