Re: get class of a method
Re: get class of a method
- Subject: Re: get class of a method
- From: Jack Brindle <email@hidden>
- Date: Sun, 22 Feb 2015 13:01:03 -0800
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