4

1) what is happening when we add NSOperation or NSInvocationOperation in NSoperationQueue?

2) What is the difference between NSoperation and NSInvocationOperation?

3) which one is the best ?

nsgulliver
  • 12,655
  • 23
  • 43
  • 64
Muthu Muthu
  • 139
  • 2
  • 9

2 Answers2

11

1. Difference Between NSoperation and NSInvocationOperation

An NSoperation object is a single-shot object—that is, it executes its task once and cannot be used to execute it again.

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.What is happening when we add NSOperation or NSInvocationOperation in NSoperationQueue

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.Which one is the best

I think the word Best may vary as per your situations :)

Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102
  • If NSoperation is single shot object,excutes only one time, how can we achieve multiple synchronous operation through NSoperation? – Muthu Muthu Oct 16 '12 at 06:59
  • 1
    yeah,, i have answered your question http://stackoverflow.com/questions/12910479/how-to-achieve-concurrent-task-through-nsoperation – Shamsudheen TK Oct 16 '12 at 08:47
0

Cocoa Is My Girlfriend has a good tutorial on the use of NSOperation and NSOperationQueue. The tutorial makes use of NSOperation to download several webpages simultaneously in separate threads.

Also Check this question NSOperation on the iPhone

Community
  • 1
  • 1
IronManGill
  • 7,222
  • 2
  • 31
  • 52