单例模式

    xiaoxiao2022-06-29  43

    #import <Foundation/Foundation.h>

    @interface BMUserInfo : NSObject

    + (instancetype)shareInstance ;

    @end

    #import "BMUserInfo.h"

    #import <SMS_SDK/SMSSDK.h>

    static id _instance;

    @implementation BMUserInfo

    + (instancetype)allocWithZone:(struct _NSZone *)zone {

        

        @synchronized (self) {

            if (_instance == nil) {

                _instance = [super allocWithZone:zone];

            }

        }

        return _instance;

    }

    + (instancetype)shareInstance {

        

        @synchronized (self) {

            if (_instance == nil) {

                _instance = [[self alloc] init];

            }

        }

        return _instance;

    }

    - (id)copyWithZone:(NSZone *)zone {

        

        return _instance;

    }

    @end

    转载请注明原文地址: https://ju.6miu.com/read-1125475.html

    最新回复(0)