Re: get class of a method
Re: get class of a method
- Subject: Re: get class of a method
- From: Alex Zavatone <email@hidden>
- Date: Mon, 23 Feb 2015 10:20:53 -0500
I'm surely speaking from ignorance here, but could one extend the runtime to store a table (NSSet?) of class methods and then at an appropriate event, either parse all the source (lame, I know) or access a class method table from the runtime?
Check out "Name angling in Objective-C" on Wikipedia to see more on this topic.
If you use class_copyMethodList() on an object you've got a table of methods for each class. You could walk all objects and check that the method's name is in there, but expect to encounter duplicate method names within classes. There's nothing I know of that would prevent that.
Might that work?
Sent from my iPad. Please pardon typos.
On Feb 23, 2015, at 1:18 AM, Maxthon Chan <email@hidden> wrote:
> In Objective-C, methods are called my sending messages, and message selectors are not bounded to a class.
>
> You can walk all loaded classes and try to work out the classes that responds to the message selector in question, but beware classes that descended from the old Object class (not NSObject or NSProxy) that does not work with (most) introspection methods and runtime functions.
>
>> On Feb 22, 2015, at 20:41, BareFeetWare <email@hidden> wrote:
>>
>> Hi all,
>>
>> How can I get the class of a method, at runtime?
>>
>> I can get the name of the class methods via:
>>
>> Method *methods = class_copyMethodList(objc_getMetaClass([NSStringFromClass([self class]) UTF8String]), &methodCount);
>> for (int i = 0; i < methodCount; i++) {
>> Method method = methods[i];
>> NSString *methodName = NSStringFromSelector(method_getName(method));
>>
>>
>> And I can get the "returnType" via:
>>
>> char *returnType = method_copyReturnType(method);
>> NSLog(@"The return type is %s", returnType);
>>
>>
>> However, the returnType is just a char that is set to "@" for all classes. I want to know which class is returned.
>>
>> References:
>>
>> Apple's documentation on the Objective C runtime library:
>> https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/index.html
>>
>> This article points to some private methods in NSObject that will return the full syntax of the method header, but is as clueless as I am as to how they get the class:
>> http://bou.io/ExtendedTypeInfoInObjC.html
>>
>> Any introspective answers out there?
>>
>> Thanks,
>> Tom
>>
>> Tom Brodhurst-Hill
>> BareFeetWare 👣
>>
>> --
>> iPhone/iPad/iPod and Mac software development, specialising in databases
>> email@hidden
>> --
>> Follow us on Twitter: http://twitter.com/barefeetware/
>> Like us on Facebook: http://www.facebook.com/BareFeetWare
>>
>> _______________________________________________
>>
>> 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
>
> _______________________________________________
>
> 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
_______________________________________________
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