问题描述
1)当我们在 NSoperationQueue中添加
? NSOperation
或 NSInvocationOperation
时发生的情况
1) what is happening when we add NSOperation
or NSInvocationOperation
in NSoperationQueue
?
2) NSoperation
和之间有什么区别NSInvocationOperation
?
3)哪一个最好?
推荐答案
1。 NS操作与NSInvocationOperation之间的差异
NSoperation 对象是一次性对象 - 也就是说,它执行一次任务,不能再用来执行它。
An NSoperation object is a single-shot object—that is, it executes its task once and cannot be used to execute it again.
NSInvocationOperation 类是NSOperation的具体子类,它管理指定为单个封装任务的执行一个调用。您可以使用此类来启动包含在指定对象上调用选择器的操作。此类实现非并发操作。
The NSInvocationOperation class is a concrete subclass of NSOperation that manages the execution of a single encapsulated task specified as an invocation. You can use this class to initiate an operation that consists of invoking a selector on a specified object. This class implements a non-concurrent operation.
2.当我们在NSoperationQueue中添加NSOperation或NSInvocationOperation时发生了什么
您通常通过将操作添加到操作队列(NSOperationQueue类的实例)来执行操作。操作队列通过在辅助线程上运行它们直接执行其操作,或者间接使用libdispatch库(也称为Grand Central Dispatch)执行其操作
You typically execute operations by adding them to an operation queue (an instance of the NSOperationQueue class). An operation queue executes its operations either directly, by running them on secondary threads, or indirectly using the libdispatch library (also known as Grand Central Dispatch)
3。哪一个是最好的
我认为最佳这个词可能因您的情况而异:)
I think the word Best may vary as per your situations :)
这篇关于NSOperation和NSInvocationOperation之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!