Passing a class or protocol as an argument
Passing a class or protocol as an argument
- Subject: Passing a class or protocol as an argument
- From: Andrew White <email@hidden>
- Date: Fri, 29 Sep 2006 13:48:01 +1000
I have a slightly odd situation.
Here's a simplified example:
- (void) someMethod: (Class) class someArg: (id) arg
{
[class performClassMethodWithArg: arg];
}
Unsurprisingly, the compiler complains that
"warning: no '+performClassMethodWithArg:' method found".
Is there some way to type that parameter as "a class that supports this
class method"? If it were an object, I could use a protocol. Is there an
equivalent for classes?
Although I'd rather not be restricted to a specific class hierarchy, I did try
- (void) someMethod: (MyClass) class someArg: (id) arg
but the compiler complained that
"error: can not use an object as parameter to a method"
Any suggestions?
As to why? performClassMethodWithArg is actually a constructor that
creates a new object of type 'class' using 'arg' as input. It's in the
middle of a loop (ie input is an array of arg of varying type but
conforming to a particular protocol) that normalises and extends 'arg'.
While the specific types of 'class' and 'arg' vary I want to perform the
same operation on them.
--
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