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 protected]> > 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 protected] > -- > Follow us on Twitter: http://twitter.com/barefeetware/ > Like us on Facebook: http://www.facebook.com/BareFeetWare > > _______________________________________________ > > Cocoa-dev mailing list ([email protected]) > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/max%40maxchan.info > > This email sent to [email protected]
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list ([email protected]) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
