Invoking protocol method on the main thread
Invoking protocol method on the main thread
- Subject: Invoking protocol method on the main thread
- From: Graham Cox <email@hidden>
- Date: Fri, 16 Nov 2012 10:17:57 +1100
Hi all,
I have a formal protocol for a notification callback I want to make. The protocol inherits the NSObject protocol.
The caller accepts only objects conforming to this protocol as its delegate. When it's time to invoke the callback, I'd like to do so on the main thread, since the caller can be running on another thread. But -performSelectorOnMainThread:withObject:waitUntilDone: is not part of the NSObject protocol, it's part of the methods of NSObject, so my code won't compile because id<MyProtocol> objects don't include this method.
How can I invoke a method of my protocol on the main thread?
@protocol MyProtocol<NSObject>
- (void) foo:(Caller*) caller;
...
@interface Caller : NSObject
@property (assign) id<MyProtocol> delegate;
...
[self.delegate performSelectorOnMainThread:@selector(foo) withObject:self waitUntilDone:NO]; // method not found
--Graham
_______________________________________________
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