IOS obtains the instance method list of a class.

Source: Internet
Author: User

To be referenced:

# Import <Foundation/nsobjcruntime. h>

# Import <objc/runtime. h>

Implementation

 

Class currentclass = [common class];

 While (currentclass ){

 Unsigned int methodcount;

 Method * methodlist = class_copymethodlist (currentclass, & methodcount );

 Unsigned int I = 0;

 For (; I <methodcount; I ++ ){

 Nslog (@ "% @-% @", [nsstring stringwithcstring: class_getname (currentclass) encoding: nsutf8stringencoding], [nsstring stringwithcstring: sel_getname (method_getname (methodlist [I])
Encoding: nsutf8stringencoding]);

 }

  

 Free (methodlist );

 Currentclass = class_getsuperclass (currentclass );

 }


(Smking: I tried it. It is indeed feasible, and in objc/runtime. h. Search for class_copymethodlist in the help document. You can see a considerable number of runtime methods. You can also find a way to replace existing classes. In the runtime process, this allows you to intercept events, you can traverse the methods of this class and then replace a special method to invalidate the purpose .)

From: http://blog.sina.com.cn/s/blog_6d01cce30101e4ab.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.