#import <Foundation/Foundation.h>
@interface AccountManager : NSObject <NSCopying>
+ (instancetype)sharedAccountManager;
@end
#import "AccountManager.h"
@implementation AccountManager
static AccountManager *instance;
+ (instancetype)sharedAccountManager
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[AccountManager alloc] init];
});
return instance;
}
+ (instancetype)allocWithZone:(struct _NSZone *)zone
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [super allocWithZone:zone];
});
return instance;
}
- (id)copyWithZone:(NSZone *)zone
{
return instance;
}
- (oneway void)release
{
// 什么都不做
}
- (instancetype)retain
{
return instance;
}
- (instancetype)autorelease
{
return instance;
}
/// 永远保证引用计数为1
- (NSUInteger)retainCount
{
return 1;
}
@end