标签:
#import <Foundation/Foundation.h>
@interface RYSingleExample : NSObject<NSCopying>
+(instancetype)singleExample;
@end
#import "RYSingleExample.h"
static id _single;
@implementation RYSingleExample
+(instancetype)singleExample
{
if(_single==nil)
{
@synchronized(self)
{
if (_single==nil) {
_single=[[self alloc]init];
}
}
}
return _single;
}
+(instancetype)allocWithZone:(struct _NSZone *)zone
{
if(_single==nil)
{
@synchronized(self)
{
if (_single==nil) {
_single=[super allocWithZone:zone];
}
}
}
return _single;
}
-(id)copyWithZone:(NSZone *)zone
{
return _single;
}
@end
标签:
原文地址:http://www.cnblogs.com/tangranyang/p/4713678.html