• 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: Difference between SEL and const char* when sending a message?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Difference between SEL and const char* when sending a message?


  • Subject: Re: Difference between SEL and const char* when sending a message?
  • From: Marcel Weiher <email@hidden>
  • Date: Tue, 7 Apr 2009 23:29:23 -0700


On Apr 7, 2009, at 20:34 , Daqi Pei wrote:

Hi everyone. I'm new to Objective-C but I've been working with C++ for
years. I'm trying to understand how the selector mechanism works.

I think the best reference for that would be Brad Cox's original book on Objective-C.


In short: selectors *are* uniqued strings in the Apple runtime, and the pointers to those strings are used as unique values to distinguish messages. However, that is an implementation detail that you shouldn't rely on. In the GNU runtime, for example, selectors are structures that contain type information in addition to the selector name.

My hypothesis works well with method calls with no parameters. e.g. , you
cal write:


[myObj performSelector: (SEL)"someMethod"];

That is a lucky coincidence, probably because compiler and linker do some string uniquing for you that happily coincides with the selector uniquing in this particular case.


Though when it comes to method with parameters, it looks like a total
different story.

Looks like your luck ran out... :-) There are many reasons why it could/would, so I really wouldn't rely on that sort of luck. One reason being that, as far as I know, only the static linker uniques strings, whereas selectors are uniqued across dynamic libraries using a bit of indirection and a reconciliation step at app startup.



NSSelectorFromString(); works fine, but the approach above throws exceptions.

Anyone knows why? Thanks.

Because it's part of the documented API and actually does what is necessary?


Cheers,

Marcel

_______________________________________________

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


References: 
 >Difference between SEL and const char* when sending a message? (From: Daqi Pei <email@hidden>)

  • Prev by Date: Re: Does waitUntilExit really mean that?
  • Next by Date: Sqlite3
  • Previous by thread: Re: Difference between SEL and const char* when sending a message?
  • Next by thread: How to find whether the file directory is a valid Mac OS X App?
  • Index(es):
    • Date
    • Thread