Question

On iOS/Objective-C, given an executing NSBlockOperation, is it possible to determine which queue the operation is associated with? Determining if one is on the main thread is pretty obvious, but what about operations in the background?

Était-ce utile?

La solution

How about

[NSOperationQueue currentQueue];

From the docs:

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.

Autres conseils

There is a DEPRECATED method: dispatch_get_current_queue()

BUT apple really doesn't like it because it isn't safe or may lead to deadlocks or .. I didn't fully get the issue ;)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top