Unveiling the mystery of runtime

Unveiling the mystery of runtime

[[164970]]

I recently wanted to change jobs, and I was full of confidence, but I didn't know the weak points of my knowledge until the interview. So I started to learn runtime to address my weak points in interviews. The following will use my learning process to explain runtime, which is very important but also very broad. I hope it can help you who are confused. It can also serve as my own study notes.

What is runtime?

Runtime literally means running time, run (run, run) time (time). Everyone on the Internet calls it runtime. It is a set of relatively low-level pure C language APIs, belonging to a C language library, which contains many low-level C language APIs. It is the behind-the-scenes worker of OC. The OC code we usually write will be converted into runtime C language code during the running process.

What is runtime used for?

If you don't know runtime before, you may think it is useless, but it is actually very powerful. Let's unveil the mystery of runtime in the form of code.

Function 1 Get all member variable names of a class (if your members are private, you can also get them)

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

These member variables are all public. We can see them by clicking on the beginning file. If it is a system class, you may not know which members are in the class. You can easily solve this problem by using runtime. Now let's test it. Remember to add #import

Printing Results

You can try putting all members into the .m file, and the print result is the same.

Function 2 Similarly, we can get all the attribute names of a class

Print results:

Function 3 Get all methods of a class

Print results:

We can see all the methods

Function 4 Get all protocols followed by a class

First comment out the protocol to be followed

Test code

Nothing was printed out.

We open the code comments that follow

Execute the test code again and print the results

Isn't it great? You may think it's not very useful, so let's take a look at how to use runtime to archive and unarchive.

Function 5: Archive/Unarchive

The test is as follows

Print results:

Isn’t it much simpler than archiving and unarchiving before?

The role of runtime is so important that I didn't know it until I learned it. This is my learning process and some experience today. I will continue to share my learning process with you in the future, hoping to give you some help.

<<:  Bad example: Five steps to make your website slow down

>>:  Wild Dog Programmer Independence Day Rock Music Festival will be held on April 8

Recommend

You may not have heard of "Pistachio", but you have definitely eaten it!

Today’s hot topic comes from this guy in the comm...

How to plan an efficient App marketing operation plan!

In recent years, mobile Internet has developed ra...

Frogfish: The world's most powerful and fastest mouth

Frog fish walks A silly and laborious look leisur...

Experts say: This is an iOS development skill that you can’t miss (Part 3)

Swift 2 is out, and we have to keep up with the t...

Is there a healthiest snack that won’t make you fat? Yes and no

Snacks include not only fruits, nuts and potato c...

Qinling Station, rising from the ice field

The original title of this article is "Qinli...

How do new media operators choose popular content?

Everyone who works in new media must have thought...

52 years later, Dongfanghong-1 is still flying in the sky? !

This article was reviewed by Liu Yan, Space Appli...