NSOperationQueue,NSOperation

给你一囗甜甜゛ 提交于 2019-12-24 10:20:10

问题


I m new to iphone. where i get examples for NSOperationQueue, NSOperation?
What is the advantage of NSOperationQueue, NSOperation over thread?

Thanks


回答1:


Read the docs. They are really good at explaining and giving examples

http://developer.apple.com/library/ios/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationObjects/OperationObjects.html%23//apple_ref/doc/uid/TP40008091-CH101-SW1

NSOperation is easier to manage than NSThread.




回答2:


Higher level of abstraction: That is, easier to program than NSThreads and a little bit less control than NSThread.




回答3:


NSOperationQueue:

An NSOperationQueue object is a queue that handles objects of the NSOperation class type. The NSOperationQueue handles and manages the execution of all the NSOperation objects (the tasks) that have been added to it. The execution takes place with the main thread of the application. When an NSOperation object is added to the queue it is executed immediately and it does not leave the queue until it is finished. A task can be cancelled, but it is not removed from the queue until it is finished.

NSOperation:

NSOperation is designed to handle more-or-less batch operations. An NSOperation object, simply phrased,represents a single task, including both the data and the code related to the task. The NSOperation class is an abstract one so it cannot be used directly in the program. Instead, there are two provided subclasses, the NSInvocationOperation class and the NSBlockOperation class.

OfCourse for more details Apple iOS Developer Library is the best option and the link below would also help to know more about it and NSOperationQueue, NSOperation VS thread.

NSThread vs. NSOperationQueue vs. ??? on the iPhone

http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues



来源:https://stackoverflow.com/questions/5190917/nsoperationqueue-nsoperation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!