<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>“我”的开发笔记 &#187; Q&amp;A</title>
	<atom:link href="http://c.gzl.name/archives/category/qa/feed" rel="self" type="application/rss+xml" />
	<link>http://c.gzl.name</link>
	<description>IPhone, Cocoa, PHP, Javascript, JQuery, Actionscript, etc...</description>
	<lastBuildDate>Thu, 29 Dec 2011 07:20:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>答问留言：关于NSOperation</title>
		<link>http://c.gzl.name/archives/444</link>
		<comments>http://c.gzl.name/archives/444#comments</comments>
		<pubDate>Fri, 04 Sep 2009 00:12:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[10 - 性能调试]]></category>
		<category><![CDATA[Cocoa开发]]></category>
		<category><![CDATA[Q&A]]></category>
		<category><![CDATA[iPhone开发]]></category>
		<category><![CDATA[NSInvocationOperation]]></category>
		<category><![CDATA[NSOperation]]></category>
		<category><![CDATA[NSOperationQueue]]></category>

		<guid isPermaLink="false">http://c.gzl.name/?p=444</guid>
		<description><![CDATA[1，operationQueue 里边应该可以同时添加多个operation吧？ 是的，本来operationQueue的目的就是多线程管理，那多线程，可不只是一个线程。 而且我们可以设置这个队列每次被处理的“操作”数量 NSOperationQueue *aQ = &#91;&#91;NSOperationQueue alloc&#93; init&#93;; &#91;aQ setMaxConcurrentOperationCount:10&#93;; 这里的setMaxConcurrentOperationCount就是同时被处理的“操作数”，参数为整数int或NSInteger (两个是一样的，不记得的可以在我的博客里面搜索一下噢～) 2，那main函数应该怎么写？ main函数中其实只需要写你要在另外一个进程里面作的事情。比如对于我来说，我常常只是作一个简单的事情，那我会用NSInvocationOperation，NSOperation的简化版。比如说： NSInvocationOperation *aOpt = &#91;&#91;NSInvocationOperation alloc&#93; initWithTarget:self selector:@selector&#40;doSomeThing&#41; object:nil&#93;; &#160; - &#40;void&#41;doSomeThing &#123; //读取大量大延迟数据等等 //可以使用performSelectorOnMainThread来将得来的数据返回到主线程 &#125; 在doSomeThing函数里面，我可以从网上读取一些东西，但是读取是需要占用时间，而堵塞主线程的。而使用NSOperation这样使用就不会了。 而如果是NSOperation，虽然复杂了一些，又是做一个NSOperation的子类。其实main函数做得事情和doSomeThing是一抹一样的。只不过如果你制作这个子类，你对其操作的内容可以更多，可以制作更复杂的读取，载入操作等等，而且你可以重复使用这个类功能阿。再者，NSOperation也提供了对runtime操作的支持，不过那就太麻烦了，一般不大用的上。 最近麻烦事情真是太多了，而且还都不顺利，死的心都有阿。还好有这么多好朋友支持我，我这个博客也一点儿一点儿的有回复了&#8230;大家别那么冷漠，管我写的好还是不好，按东北话来说“吱一声”嘛～唉，我要加油阿！我还有那么多的事情没办到呢，怎么能放弃！他妈的！！！！！阿！！！！！！]]></description>
		<wfw:commentRss>http://c.gzl.name/archives/444/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

