Is it safe to enumerate, via fast enumeration, through [NSOperationQueue operations]
? Like so:
for (NSOperation *op in [operationQueue operations]) {
// Do something with op
}
Since operations are asynchronous and executed on another thread, operations
could change at any time (including during the main thread's execution). Does fast enumeration protect against this, or should I copy
(and autorelease
) the operations array instead?
It's only unsafe if the queue mutates the array while you're enumerating it.
However:
Returns a new array containing the operations currently in the queue.
The word “new” in there suggests to me that the queue will do the copy and autorelease for you, so you can safely enumerate through the array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With