Runtime sorting and runtime sorting

Source: Internet
Author: User

Runtime sorting and runtime sorting

1. Runtime is written in C and sink.

  • For the C language, function calls determine which function to call during compilation. For OC functions, they are a dynamic call process. During compilation, they cannot decide which function to call, the corresponding function can be called only when the function is running.

Ii. Common Runtime header files

# Import <objc/runtime. h>

# Import <objc/message. h>

Iii. Common Runtime functions

Class_copyIvarList: obtains the member variable within a class.

Class_copyMethodList: obtains all the methods in a class.

Class_getInstanceMethod: obtains a specific instance method.

Class_getClassMethod: obtains a specific class method.

Class_getMethodImplementation: Get method implementation

Method_exchangeImplementations: implements the exchange of two methods

Objc_msgSend: send messages to objects

Class_addMethod: Add Method

Objc_getAssociatedObject: obtains the associated value based on the associated key.

Objc_setAssociatedObject: Set Association attributes

4. Use Cases of Runtime

Send message

Exchange Method

Dynamically generate attributes and Methods

Call action directly through block callback

Archive and archive

Dictionary-to-Model

5. Specific implementation of various Runtime scenarios

1. Send messages

Note:

  

  

2. Exchange Methods

Because the system method, such as imageNamed, cannot be rewritten directly in a category, this will overwrite the system function, and super cannot be called in the category, so the exchange method must be used instead of rewriting.

  

3. dynamically generate attributes and Methods

If a class has many methods and resources are compared when the class is loaded to the memory, you need to generate a ing table for each method. The dynamic generation method solves this problem.

 

 

Dynamically add attributes

4. Call action directly through block callback

// Call action directly through block callback

5. Archive and archive

  

  

  

6. dictionary-to-model conversion

KVC: traverses all keys in the dictionary and searches for corresponding attribute names in the model.

Runtime: traverses all attribute names in the model and searches for them in the dictionary.

  

  

 

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.