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

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


  • Follow-Ups:
    • Re: Passing a class or protocol as an argument
      • From: Chris Suter <email@hidden>
  • Prev by Date: Re: Dragging a file and place it inside a Menu
  • Next by Date: Re: Passing a class or protocol as an argument
  • Previous by thread: [SOLVED] Truncating the string value of an NSTextField, in a Panther compatible way.
  • Next by thread: Re: Passing a class or protocol as an argument
  • Index(es):
    • Date
    • Thread