• 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: Passing a class or protocol as an argument
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passing a class or protocol as an argument


  • Subject: Re: Passing a class or protocol as an argument
  • From: Chris Suter <email@hidden>
  • Date: Fri, 29 Sep 2006 15:03:56 +1000

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:

This email sent to email@hidden

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

  • Prev by Date: Passing a class or protocol as an argument
  • Next by Date: Help Book not working
  • Previous by thread: Passing a class or protocol as an argument
  • Next by thread: Help Book not working
  • Index(es):
    • Date
    • Thread