• 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
Calling a class method with the runtime ObjC API
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calling a class method with the runtime ObjC API


  • Subject: Calling a class method with the runtime ObjC API
  • From: vincent habchi <email@hidden>
  • Date: Thu, 18 Nov 2010 22:18:22 +0100

Hi there,

this is more a style question than anything else, but I'm sometimes perfectionist. ;) I am also aware it is somewhat borderline with Cocoa (belongs more to ObjC in general); sorry for this.

I have designed a kind of a fake class which is, in reality, a simple collection of algorithms implemented as class methods. They all take the same three arguments, however. The user can pick up an algorithm by selecting a conventional name in a popup button. Then the code is supposed to call the selected class method, whose selector is known through a simple dictionary lookup.

I supposed I couldn't do such a simple thing as [MyClass perform:selector] because the perform: method is an instance one. So I wrote this:

Method	theAlgorithmMethod = class_getClassMethod ([MyClass class], theAlgorithm);
IMP	itsImplementation = method_getImplementation (theAlgorithmMethod);
result = (* itsImplementation)(self, algorithm, …)

which works fine. But is there a clever way to achieve this?

Thanks a lot,
Vincent_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Calling a class method with the runtime ObjC API
      • From: Greg Parker <email@hidden>
    • Re: Calling a class method with the runtime ObjC API
      • From: Joar Wingfors <email@hidden>
  • Prev by Date: Re: On self = [super init...] ...
  • Next by Date: Re: Calling a class method with the runtime ObjC API
  • Previous by thread: Re: On self = [super init...] ...
  • Next by thread: Re: Calling a class method with the runtime ObjC API
  • Index(es):
    • Date
    • Thread