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
Today’s hot topic comes from this guy in the comm...
Author: Chen Wen Reviewer: Qin Zongmin With the l...
In recent years, mobile Internet has developed ra...
Frog fish walks A silly and laborious look leisur...
Swift 2 is out, and we have to keep up with the t...
The establishment of a Baidu bidding promotion ac...
Review expert: Zhou Hongzhi, senior laboratory te...
Snacks include not only fruits, nuts and potato c...
The original title of this article is "Qinli...
Everyone who works in new media must have thought...
This article was reviewed by Liu Yan, Space Appli...
According to media reports, Tesla's previousl...
These days, WeChat 8.0 has completely dominated t...
As a content carrier that is suitable for use in ...