objective-c单例类实现
来源:互联网 发布:软件开发编码规范 编辑:程序博客网 时间:2024/05/17 21:58
- //Singleton类声明
- #import <Foundation/Foundation.h>
- @interface Singleton :NSObject
- +(Singleton*)GetInstance;
- -(void)SayHello;
- @end
- //Singleton类实现
- #import "Singleton.h"
- @implementation Singleton
- static Singleton *myInstance =nil;
- +(Singleton*)GetInstance{
- @synchronized([Singleton class]){
- if(myInstance ==nil){
- myInstance = [[self alloc]init];
- }
- }
- return myInstance;
- }
- +(id)alloc{
- @synchronized([Singleton class]){
- if (myInstance ==nil) {
- myInstance = [super alloc];
- return myInstance;
- }
- }
- return nil;
- }
- -(id)init{
- self = [super init];
- if(self !=nil){
- NSLog(@"初始化数据");
- }
- return self;
- }
- -(void)SayHello{
- NSLog(@"Hello,world!");
- }
- @end
- //================================================
- Main方法调用
- #import <Foundation/Foundation.h>
- #import "Singleton.h"
- int main (int argc,const char * argv[])
- {
- @autoreleasepool{
- Singleton *singleton = [Singleton GetInstance];
- [singleton SayHello];
- singleton = [Singleton new];
- [singleton SayHello];
- }
- return 0;
- }
- 原文链接:http://blog.csdn.net/lanergaming/article/details/7597267
- objective-c单例类实现
- objective-c单例类实现
- objective-c 单例类的简单实现
- Objective-C 队列实现
- Objective-C底层实现
- Objective-C单例实现
- Objective C实现多继承!
- objective-c sha1加密实现
- Objective C实现多继承
- Objective C 单例实现
- objective-c 页面返回实现
- Objective C实现多继承
- Objective-C 的底层实现
- 表达式求值:Objective-C实现
- Objective-C锁的实现
- sieve的objective-c实现
- Objective C实现多继承!
- Objective-C实现信用卡校验
- Qt入门-界面多语言国际化的实现
- 关于浮躁
- zoj分类
- c++ 结构和类
- JSF h:datatable 循环取值 两列值
- objective-c单例类实现
- 线程总结
- 二分图最大匹配 建图
- WinForm复制窗体,重命名后报错
- VA_LIST的用法
- 数据库相关
- facebook ios sdk 无法登出bug的解决方法
- 黄泉饮茶----第十七层地狱
- ORA-00600 internal error code,arguments