0

How can i set the priority in NSOperationQueue to not execute the next operation until the previous operation is finished?

   NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
  [operationQueue setMaxConcurrentOperationCount:1];
   NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(addPhotoWithButton:) object:button];
  [operationQueue addOperation:operation];
  [operation release];
Ziad.T
  • 119
  • 4
  • This sentence is confusing and I suspect that you meant "How can i set the priority in NSOperationQueue to NOT execute the next operation until the previous operation is finished?". Note the added "not". If this is indeed the case then you should update your question. – Jon Steinmetz Apr 24 '12 at 00:46

1 Answers1

1

Assuming that you mean that you want to execute the operations serially or one at a time then I think your problem is that you are calling setMaxConcurrentOperationCount: with 1 and then losing the reference to that operation queue by overwriting it with another operation queue. So what you are doing is correct, you just need to add the operation to the queue with the desired operation count. You probably did not mean to do this, in fact, I would think you would be seeing a compiler warning. Try this code:

NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
[operationQueue setMaxConcurrentOperationCount:1];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(addPhotoWithButton:) object:button];
[operationQueue addOperation:operation];
[operation release];
Jon Steinmetz
  • 4,104
  • 1
  • 23
  • 21