RE: Interrogating selectors at runtime
RE: Interrogating selectors at runtime
- Subject: RE: Interrogating selectors at runtime
- From: email@hidden
- Date: Mon, 6 Feb 2006 08:21:05 +0100
- Thread-topic: Interrogating selectors at runtime
Question 1, SEL args at runtime, yes. You want to be looking at
NSMethodSignature object, which can be created via a SEL type.
Check out NSObject's methodSignatureForSelector: class method.
There is also a C function which can tell you the number of arguments,
and their types - but this requires an objective-c method definition.
The type information returned is the 'const char *' text result of an
@encode() operation - which will be a bunch of funny symbols. It
depends on what you are trying to do with those symbols as to how in
depth you want to go in parsing them. For simple/primitive data types
you'll be OK with a lookup dictionary, anything more complex and you
might want a parser (I've got one for *exactly* this task in my project
for SymbolExplorer, ask if you want it).
You'll find the #defines for these primitives in the objc/obj-class.h
file. There's loads more information in the The Objective-C Programming
Language document (available in your online docs, and from your local
http://developer.apple.com/ website) :-)
Question 2, no idea - I imagine that the extra argument would NOT be
discarded, check it out with a simple test program perhaps? See what
happens...
John
-----Original Message-----
From: cocoa-dev-bounces+john.clayton=email@hidden
[mailto:cocoa-dev-bounces+john.clayton=email@hidden] On
Behalf Of Andrew White
Sent: Montag, 6. Februar 2006 00:58
To: Cocoa Users
Subject: Interrogating selectors at runtime
Given a data entry of type SEL, is there an easy way to find out how
many arguments it expects at runtime?
Obviously, I can go NSStringFromSelector (aSelector) and then count the
number of ':' characters, but that's expensive and clunky. Is there a
better way?
A related question: what happens if I call 'performSelector:withObject'
on a selector that takes no arguments, or
'performSelector:withObject:withObject' on a selector that takes only
one?
Are the surplus arguments harmlessly discarded?
eg:
SEL aSelector = @selector (myMethod:)
[aClassInstance performSelector: aSelector
withObject: anObject
withObject: anotherObject
];
Will this harmlessly perform [aClassInstance myMethod: anObject] or will
errors result?
Thanks
--
Andrew White
------------------------------------------------------------------------
--
This email and any attachments may be confidential. They may contain
legally
privileged information or copyright material. You should not read, copy,
use or disclose them without authorisation. If you are not an intended
recipient, please contact us at once by return email and then delete
both
messages. We do not accept liability in connection with computer virus,
data corruption, delay, interruption, unauthorised access or
unauthorised
amendment. This notice should not be removed.
_______________________________________________
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
Visit our website at http://www.ubs.com
This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail. Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.
E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses. The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission. If
verification is required please request a hard-copy version. This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.
_______________________________________________
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