Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passing a class or protocol as an argument



When calling class methods on objects declared as the class type, the compiler will only warn if it's never seen that class method anywhere. So all you need to do is declare it in an interface somewhere and the warning will go away.

This would do:

@interface NSObject (MyExtensions)
+ (void)performClassMethodWithArg:(id)arg;
@end

- Chris

On 29/09/2006, at 1:48 PM, Andrew White wrote:

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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >Passing a class or protocol as an argument (From: Andrew White <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.