I have class MyOperation : NSOperation with @property (nonatomic, retain) NSString *oID;
And sometimes I need to cancel operation with specific oID. I’m trying to do this:
NSArray *operations = operationQueue.operations;
NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat: @"oID == %@", _specificID]];
NSArray *arrayOperations = [operations filteredArrayUsingPredicate: predicate];
and get error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "oID == 0f5db97b-f127-4425-ad79-451d1f204016"'
Is it possible to filter operation from NSOperationQueue?
Your problem is that you are formatting a string, then sending that to the Predicate constructor method. It’s already a formatter, and knows how to format the data you give it.
Basically, you need the format to look like:
but you are getting
If you use the formatter by itself, you should get past this issue…
NOTE: The predicate formatter knows it should handle strings specially, and automatically adds the extra quotation characters when you pass a string to be formatted by
%@‘