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

The iPhone 6s's camera is no longer the king of mobile photography

Apple's iPhone series has brought many new mo...

Who are the people who choose to buy 4G mobile phones now?

Although 5G mobile phones are already very common...

Case Analysis | How did Zhangmen 1-on-1 grow from 0 to 300,000 users?

Faced with high public domain customer acquisitio...

iOS 12.5.1 official version released, dedicated to older models

Apple has been on vacation, and it feels like we ...

Pulse advertising analysis!

The purpose of advertising is to reduce communica...

The second half of search: Will WeChat do big search?

[[378650]] In the just-concluded WeChat 2021 Open...

Promotion account structure diagram, how to build a promotion account structure?

The account structure of search promotion consist...

My understanding of APP operation and promotion!

Today I would like to discuss some issues with my...

6 minutes to fully understand the App message push strategy

Proper use of push can help product operators ach...

Video operation skills and methods

With the rise of short videos such as Tik Tok, sh...

Kuaishou Promotion: 8 most popular tricks on Kuaishou!

There is a saying circulating on the Internet: Do...

What does it take to place an ad on TikTok? How to advertise on TikTok?

In an environment where market demand is increasi...