Search code examples
iosobjective-cnsoperationqueue

NSOperationQueue operation self


I need help with NSOperationQueue. What will happen if I will write code like this

NSOperationQueue *myqueue = [[NSOperationQueue alloc] init];
[myqueue addOperation:self];

I know that using gcd will be better, but i`m still curious

Thank you


Solution

  • if you write this code in your Viewcontroller.m

    NSOperationQueue *myqueue = [[NSOperationQueue alloc] init];
    [myqueue addOperation:self];
    

    then self will represent the Your viewController class. you can not do this.

    The two classes that we can use directly are:

    NSBlockOperation – Use this class to initiate operation with one or more blocks. The operation itself can contain more than one block and the operation will be considered as finish when all blocks are executed.

    NSInvocationOperation – Use this class to initiate an operation that consists of invoking a selector on a specified object

    for more info plz read this link http://www.appcoda.com/ios-concurrency/