• 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: Programmatically determining number of arguments a selector takes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programmatically determining number of arguments a selector takes


  • Subject: Re: Programmatically determining number of arguments a selector takes
  • From: glenn andreas <email@hidden>
  • Date: Fri, 3 Jun 2005 08:36:57 -0500


On Jun 3, 2005, at 3:30 AM, Andrew White wrote:


I have some callback code that requires the user to pass in a selector. I'd like to validate that the selector is of the correct form - it must take exactly one argument.


I've searched through the doco and have not been able to find a function that will tell me how many args an object of type SEL requires. Does something like this exist?


You could look through the selector as a string and count the number of ":" (technically, this works based entirely on the syntax of Objective-C - nothing in the runtime enforces this - a selector is basically just string).



Is there an easy way to allow such selectors to return 'void', or is it simpler to just ignore the (id) return value? NSInvocation is a bit heavyweight for what I'm doing.


NSMethodSignature is what encapsulates the number of parameters, and sizes of each of these parameters, including the return value. Since a selector is just a string, it has no such knowledge of this (witness by code like "[someId length]" causes compiler warnings because it doesn't know if you mean the length method of NSData which returns an unsigned, or the length method of NSStatusItem which returns a float). You need to explicitly ask the object (or it's class) for the signature for a given selector, because that's the place that knows all the details.


NSInvocation combines the method signature (to know how to manipulate the stack when calling the method) with a selector and target to enable you to call arbitrary methods


Glenn Andreas email@hidden <http://www.gandreas.com/> wicked fun! Widgetarium | the quickest path to widgets

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Programmatically determining number of arguments a selector takes
      • From: Damien Bobillot <email@hidden>
References: 
 >Programmatically determining number of arguments a selector takes (From: Andrew White <email@hidden>)

  • Prev by Date: Re: ScreenSaverView/NSQuickDrawView/Opaque issue [update]
  • Next by Date: Re: ScreenSaverView/NSQuickDrawView/Opaque issue [update]
  • Previous by thread: Programmatically determining number of arguments a selector takes
  • Next by thread: Re: Programmatically determining number of arguments a selector takes
  • Index(es):
    • Date
    • Thread