Calling a class method with the runtime ObjC API
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