• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Invoking protocol method on the main thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Invoking protocol method on the main thread


  • Subject: Re: Invoking protocol method on the main thread
  • From: Greg Parker <email@hidden>
  • Date: Thu, 15 Nov 2012 15:23:49 -0800

On Nov 15, 2012, at 3:17 PM, Graham Cox <email@hidden> wrote:
> 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

The simple solution is to declare your property as NSObject<MyProtocol>* .


--
Greg Parker     email@hidden     Runtime Wrangler



_______________________________________________

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

  • Follow-Ups:
    • Re: Invoking protocol method on the main thread
      • From: Graham Cox <email@hidden>
References: 
 >Invoking protocol method on the main thread (From: Graham Cox <email@hidden>)

  • Prev by Date: Invoking protocol method on the main thread
  • Next by Date: Re: Invoking protocol method on the main thread
  • Previous by thread: Invoking protocol method on the main thread
  • Next by thread: Re: Invoking protocol method on the main thread
  • Index(es):
    • Date
    • Thread