iOS 单例模式
来源:互联网 发布:贵金属数据下载 编辑:程序博客网 时间:2024/06/10 01:33
#import <Foundation/Foundation.h>
@interface Singleton :NSObject
+ (Singleton *)sharedSingleton;
+ (void)purgeSharedSingleton;
@end
#import "Singleton.h"
@implementation Singleton
staticSingleton* sInstance = nil;
+ (Singleton *)sharedSingleton
{
@synchronized(self) {
if (sInstance == nil) {
[[selfalloc] init];
}
}
returnsInstance;
}
+ (void)purgeSharedSingleton
{
if (sInstance) {
[sInstancerealRelease];
}
}
+ (id)allocWithZone:(struct_NSZone *)zone
{
@synchronized(self) {
if (sInstance == nil) {
sInstance = [superallocWithZone:zone];
return sInstance;
}
}
returnsInstance;
}
+ (id)copyWithZone:(struct_NSZone *)zone
{
returnself;
}
- (id)copy
{
returnself;
}
- (id)retain
{
returnself;
}
- (NSUInteger)retainCount
{
return UINT_MAX;
}
- (onewayvoid)release
{
}
- (id)autorelease
{
returnself;
}
- (void)dealloc
{
sInstance = nil;
[superdealloc];
}
- (void)realRelease
{
[superrelease];
}
@end
- iOS单例模式
- iOS 单例模式
- IOS 单例模式
- iOS 单例模式
- IOS单例模式
- ios单例模式
- iOS 单例模式
- iOS 单例模式
- IOS单例模式
- iOS 单例模式
- iOS 单例模式
- IOS 单例模式
- IOS---单例模式
- iOS--单例模式
- iOS 单例模式
- ios 单例模式
- iOS 单例模式
- IOS单例模式
- Unity3D如何编写AI
- Linux常用命令英文全称与中文解释Linux系统
- java开发配置环境变量备忘
- The Wordbay Wordpress eBay® Plugin
- 移植flash游戏到android
- iOS 单例模式
- C#.ToString()格式大全
- Hacking and Securing iOS Applications Note
- cocos2dx 3.0 js继承:John Resiq的继承写法解析
- QTP/UFT中定位对象的最常见方法
- Hive:用Java代码通过JDBC连接Hiveserver
- 63-输入一个数字,判断是不是回文数字
- spring mvc i18n+freemarker
- 关于模态窗口window.showModalDialog