多线程编程资源汇总

 

iOS有三种多线程编程的技术:
1)NSThread 
2)Cocoa NSOperation (iOS多线程编程之NSOperation和NSOperationQueue的使用)
3)GCD 全称:Grand Central Dispatch( iOS多线程编程之Grand Central Dispatch(GCD)介绍和使用)
这三种编程方式从上到下,抽象度层次是从低到高的,抽象度越高的使用越简单,也是Apple最推荐使用的。
介绍参见下面文档:

 

1、iOS多线程编程之NSThread的使用

第一种方式会直接创建线程并且开始运行线程
1、[NSThread detachNewThreadSelector:@selector(doSomething:) toTarget:self withObject:nil];  


第二种方式是先创建线程对象,然后再运行线程操作,在运行线程操作前可以设置线程的优先级等线程信息
2、NSThread* myThread = [[NSThread alloc] initWithTarget:self  
                                          selector:@selector(doSomething:)  
                                          object:nil];  
[myThread start];  
2.2参数的意义:
selector :线程执行的方法,这个selector只能有一个参数,而且不能有返回值。
target   :selector消息发送的对象
argument :传输给target的唯一参数,也可以是nil

2、 iOS多线程编程之NSOperation和NSOperationQueue的使用

NSInvocationOperation例子
NSInvocationOperation *operation = [[NSInvocationOperation alloc]initWithTarget:self
                                                                 selector:@selector(downloadImage:)
                                                                 object:kURL];


NSOperationQueue *queue = [[NSOperationQueue alloc]init];
[queue addOperation:operation];

3、iOS多线程编程之Grand Central Dispatch(GCD)介绍和使用

4、多线程编程指南

 

posted @ 2013-11-17 23:29  Forrest.Wang  阅读(104)  评论(0编辑  收藏  举报