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: Sun, 22 Feb 2015 16:11:33 -0500
That's the class of the current instance.
I think the poster wants this: "I have this method. What's its class?"
On Feb 22, 2015, at 4:01 PM, Jack Brindle wrote:
> Doesn’t [self class] do this? The method is within whatever self is, so it seems appropriate that [self class]
> would provide what you want.
>
> - Jack
>
>> On Feb 22, 2015, at 4:41 AM, 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