[OC]Singleton的一种简便实现方式
2014-04-03 16:18
281 查看
static dispatch_queue_t xml_request_operation_processing_queue() { static dispatch_queue_t af_xml_request_operation_processing_queue; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ af_xml_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.xml-request.processing", DISPATCH_QUEUE_CONCURRENT); }); return af_xml_request_operation_processing_queue; }
通过dispatch_once执行一次来保证af_xml_request_operation_processing_queue只有一次实例化的机会~
这个方法能够很好的在任何类中调起单例的时候使用~
下面为singleton启一个单独的线程
+ (void) __attribute__((noreturn)) networkRequestThreadEntryPoint:(id)__unused object { do { @autoreleasepool { [[NSThread currentThread] setName:@"AFNetworking"]; [[NSRunLoop currentRunLoop] run]; } } while (YES); } + (NSThread *)networkRequestThread { static NSThread *_networkRequestThread = nil; static dispatch_once_t oncePredicate; dispatch_once(&oncePredicate, ^{ _networkRequestThread = [[NSThread alloc] initWithTarget:self selector:@selector(networkRequestThreadEntryPoint:) object:nil]; [_networkRequestThread start]; }); return _networkRequestThread; }
相关文章推荐
- ObjectARX2012学习笔记一
- ObjectARX2012学习笔记之Autodesk.AutoCAD.AcInfoCenterConn Namespace
- ObjectARX2012学习笔记之Autodesk.AutoCAD.Colors Namespace
- JNA&IOC实现反向动态调用不同dll版本
- Hibernate系列教程之二(SessionFactory配置)
- Hibernate系列教程之一(Hibernate结构)
- 开源文档管理软件Alfresco Content Management 4.0.c使用方法
- Hibernate&Spring对多数据源、多Schema的支持
- Ninject IOC<一>
- HQL略解
- 基于Pipe的PureMVC Flex框架的多核共享消息技术
- 一种B/S模式下基于JAVA反射机制的可伸缩动态加载模块的解决方案
- Compile the latest Kernel(linux-3.1-rc4) On Ubuntu Plateform
- Application called By IE on Pseudo B/S Mode
- How to build a Flex development platform based on Myeclipse8.6 & Flex4
- HttpService & WebService For Flex Develop
- 国外的一个flex入门教学~[转]
- abstract class VS interface[转]
- Bug Manager Plateform Sets
- Word For Application By C#