Ios--runtime/swizzle

Source: Internet
Author: User

What is runtime?

Runtimec also known as the runtime. is the system at the time of the operation of some mechanism.

is a set of underlying C language API(contains a lot of powerful practical C language data types,C language functions)

The OC code that we write usually turns into the runtime code at the bottom.

Such as:
Xqpersion *persion = [Xqpersion alloc] init];

[Persion Run];

At compile time, runtime will convert the above code into:

Objc_msgsend (Persion, @selector (run));

What's the use of Runtim?

Can dynamically generate, modify, delete a class, a member variable, a method.

can be get all the member variables inside a class, Method

Ivar * Class_copyivarlist: get all member variables inside a class

Method * Class_copymethodlist: Get all the methods inside a class

Method Class_getinstancemethod: Get an instance approach (object method, minus - start)

Method Class_getclassmethod: Get a class approach (plus + start)

Method_exchangeimplementations: A specific implementation of 2 methods of Exchange

What is Swizzle?

Calling a method in Objective-c is actually sending a message to an object, and the only way to find the message is by selector's name.

By using the dynamic characteristics of objective-c, the corresponding method of selector can be realized at runtime to achieve the purpose of linking to the method.

Each class has a list of methods that hold the mapping of selector's name and method implementation. IMP is a bit like a function pointer, pointing to a concrete method implementation.

Swizzle is the implementation of exchanging two methods while the program is running.

Ios--runtime/swizzle

Related Article

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.