The IOS runtime is detailed at runtime

Source: Internet
Author: User

What is runtime?

Runtime literal translation is the run time, run (run, running), time, the internet everyone calls it run, it is a relatively low level of pure C language API, belongs to a C language library, contains a lot of the underlying C language API, it is OC behind the workers, we usually write the OC code, When you run the process, it will be the C language code of runtime.

What's the use of runtime?

If you don't know the runtime before, you may find it useless, in fact, his role is very strong. Let's take the code as a way to uncover the runtime's mystery.

Role 1 Gets a class all member variable name (can also be obtained if your member is private)

We create a new person class, the. h code is as follows

These member variables are public, we directly point to the beginning of the file can be seen, if it is the class of the system, you do not know what members of the class, the use of runtime can easily solve the problem, now let's test, remember to add #import

Print results

You can try and put all the members into the. m file, and it prints the same result.

function 2 Similarly, we can get all the property names of a class

Printing results:

role 3 get all the methods of a class

Printing results:

We can see all the ways

role 4 gets all the protocols that a class follows

First, comment out the protocol you followed.

Test code

And they didn't print anything.

We take the code that we follow to open

Then execute the test code and print the results

Isn't that great, you might think it's not very useful, so let's take a look at how to use runtime to archive and document the file.

function 5 The archive/solution test is as follows:


The IOS runtime is detailed at runtime

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.