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