• 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: @selector not working with (id)anObject
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @selector not working with (id)anObject


  • Subject: Re: @selector not working with (id)anObject
  • From: Bill Bumgarner <email@hidden>
  • Date: Sat, 11 Apr 2009 19:01:10 -0700

Sigh.  Hit shift-cmd-D a bit too soon. :)

It does not seem I can invoke this on the main thread.
An NSInvocation?

[invocation performSelectorOnMainThread: @selector(invokeWithTarget:) withObject: ...whatever... waitUntilDone: NO];

Basically I just need to use a function pointer. How does Cocoa do this?

You can get the IMP if you want, but you don't need to for this.

I need to pass either someMethod or someOtherMethod and later call it with

[self performSelectorOnMainThread:theMethod withObject:nil
waitUntilDone:NO];

Is this normally done with NSStringFromSelector and NSSelectorFromString ?

This specific pattern? Yes -- encapsulating the selector in a string works just fine.


In general?  No.

Generally, if you have something that is going to be doing calculations on another thread, you would create an instance of some class that encapsulates the calculation. That class would also have the bits necessary to figure out if it needs to call someMethod or someOtherMethod on the main thread.

b.bum
_______________________________________________

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


  • Prev by Date: Re: @selector not working with (id)anObject
  • Next by Date: NSWorkspace openURL does not launch application
  • Previous by thread: Re: @selector not working with (id)anObject
  • Next by thread: NSWorkspace openURL does not launch application
  • Index(es):
    • Date
    • Thread