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

Xiaohongshu's content marketing logic

When we write articles and post short videos, we ...

"See through" the brain! Chinese scientists "new" super microscope

Author: Shi Xiangqi and Li Chuanfu Imagine that w...

Taobao promotion: Taobao mobile search traffic rules

How is Taobao Mobile search traffic distributed? ...

5 steps to early warning and user recall

In user operations , in addition to attracting ne...

Why is brand strategy the highest strategy?

What touched me most was what Mr. Jiang Nanchun p...

The marketing secret behind Lancôme’s nationwide popular promotions!

Recently, Lancôme's Spring Festival Garden Pa...

B station's "soft core" marketing

2020 is the year when Bilibili’s marketing began ...

A complete QQ group marketing promotion plan

A friend of mine who works in the gray industry o...