Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a reference to the NSOperationQueue from an NSOperation?

Is there a way to get the "parent" operation queue that the nsoperation is inside, from that same nsoperation? Something like [self getCurrentOperationQueue].

like image 688
zakdances Avatar asked Nov 23 '25 16:11

zakdances


2 Answers

You can get the current queue by calling the appropriately named +[NSOperationQueue currentQueue] from inside the running operation.

currentQueue
Returns the operation queue that launched the current operation.

+ (id)currentQueue

Return Value
The operation queue that started the operation or nil if the queue could not be determined.

Discussion
You can use this method from within a running operation object to get a reference to the operation queue that started it. Calling this method from outside the context of a running operation typically results in nil being returned.

like image 135
Joe Avatar answered Nov 25 '25 07:11

Joe


[NSOperationQueue currentQueue]

like image 25
JeremyP Avatar answered Nov 25 '25 08:11

JeremyP