NSoperation的疑惑

来源:互联网 发布:3d免费犀牛怎么编程 编辑:程序博客网 时间:2024/06/16 00:07
使用grant central dispatch queue
// 1) Add to bottom of initWithHTML:delegatebackgroundQueue = dispatch_queue_create("com.razeware.imagegrabber.bgqueue", NULL);         // 2) Add to top of deallocdispatch_release(backgroundQueue); // 3) Modify process to be the following- (void)process {        dispatch_async(backgroundQueue, ^(void) {        [self processHtml];    });    }


其实从某个意义上说nsoperation 是grand central dispatch的一种实现/ 你使用NSOperation实际还是在使用grand dispatch。应为NSoperation给人更多简便的用法:

1. 建立依赖,使得某个NSOPeration依赖/等候在另外一个上面

2. 你可以重排nsoperation,当特殊事件发生的时候。 

ASIHTTPrequest内部就大量使用了NSOPERATION;对于比较简单地使用一下多线程的,比如说需要分开的对象资源不多的,那么grant central dispatch就可以了

For this app it’s pretty simple so we just used Grand Central Dispatch directly, no need for the fancy features of NSOperation. But if you need them for your app, feel free to use it!


事实上,目前为止,只是有了基本的多线程概念。前面的路还远着呢

 Apple videos Apple videos  https://developer.apple.com/videos/

Both WWDC 2010 and 2011 have some videos that are a great introduction to what’s available.


如果你真的想深入学习西,可以看看mike的系列文章: articles on Grand Central Dispatch  :::这里简直就是专门研究这个GCD!


https://developer.apple.com/videos/wwdc/2011/... 2011的系列介绍


原创粉丝点击