Obtain details of categories on a class at runtime?

自闭症网瘾萝莉.ら 提交于 2019-12-24 10:47:20

问题


In Objective-C, is there a way to list the categories on a particular class at runtime?

With the Objective-C runtime functions I can obtain details for the class and instance methods, class hierarchy, instance variables, etc. but seemingly not the category information.

Looking at F-Script, I see that it doesn't display category information (indeed, it appears not to display methods from categories at all). On the other hand, class-dump extracts category information but this is from the binary and not at runtime.

There's a mention of struct objc_category in objc/runtime.h but this looks to be private. Is there a supported way?


回答1:


from "The Objective-C Programming Language" in the SDK doc:

Category methods can do anything that methods defined in the class proper can do. At runtime, there’s no difference.

the support for objc_category struct has been removed with modern objective-c (ios, 10.5), making this information opaque.

I'm afraid you can't get the information you want.



来源:https://stackoverflow.com/questions/18942449/how-to-get-a-method-list-from-a-category

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!