Reputation: 8977
I have a NSOperationQueue
that takes in a bunch of operation download request. The question is how do I check if I have a specific URL already on the NSOperationQueue
? Because if it's alreayd in the queue I don't want to enqueue it again.
Upvotes: 1
Views: 897
Reputation: 53561
You could subclass NSOperation
(if you haven't done so already), add a URL
property to your subclass, and check whether an operation with the URL you're about to add is already in the queue:
if (![[queue.operations valueForKey:@"URL"] containsObject:myURL]) {
//add operation...
} else {
//operation with this URL is already in the queue...
}
If you have lots of operations going on, you might want to track the URLs separately in an NSMutableSet
which is more efficient for membership testing. You'd then have to remove the URL from the set when an operation completes.
Upvotes: 3