How to cancel an NSInvocationOperation
How to cancel an NSInvocationOperation
- Subject: How to cancel an NSInvocationOperation
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Mon, 16 Apr 2012 16:07:34 +0700
I have this code:
NSMethodSignature *ms = [ self methodSignatureForSelector: @selector(someMethod:) ];
NSInvocation *inv = [NSInvocation invocationWithMethodSignature: ms ];
[ inv retainArguments ];
[ inv setSelector: @selector(someMethod:) ];
[ inv setTarget: self ];
[ inv setArgument: &a atIndex: 2 ];
NSInvocationOperation *ivo = [ [ NSInvocationOperation alloc ] initWithInvocation: inv ];
[ self.operationQueue addOperation: ivo ];
Works fine. But the documentation says: "An operation object is responsible for calling [isCanceled] periodically and stopping itself if the method returns YES."
But how do I check for "isCanceled" from within someMethod: ?
Is there something like: +[ NSOperation theOperationThisCodeIsRunningIn ]?
I tried (inside of someMethod:):
NSThread *currentThread = [ NSThread currentThread ];
if ( [ currentThread isCancelled ] ) NSLog(@"%s Cancelled",__FUNCTION__);
But this has no effect.
10.7.3
Kind regards,
Gerriet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden