What is runtime?
Runtime is also called Runtime, is a set of low-level C language API, which is one of the core of IOS internal, we usually write the OC code, the bottom is based on it to achieve.
Most of the time we just need to write the OC code, runtime system automatically in the background to do everything, so many friends of the runtime is not very important, and so on when the interview is often caught by the interviewer. I am also a novice, eat this loss, so the runtime to learn, Share them in an easy-to-understand way
The role of the Runtime
The system method can be modified through runtime, for example, we usually use Wkwebview (UIWebView) in the project to load some URLs, if the URL contains Chinese, the OC language is not able to recognize the URL. So our output URL is null, The interface is not loaded at this point, so how do we avoid this problem?
The first way, using category (Extension of Class), we first create an extension that inherits from Nsurl
Then we write a class method in this extended. h
And then in. m to implement
Finally go back to your own controller to import this extension to the header file, the original system of the urlwithstring into its own extended class method, so that we can easily navigate to why their URLs are not loaded out
So the point is, how do we use runtime to implement the method that the system provides to us? (Do not use custom methods)
First of all, we need to know that when executing the URLWithString method, the system will first call the + (void) Load method, then we use runtime in this method to modify, first import the header file #import <objc/runtime.h > then swap the system's URLWithString method with our previously customized bx_urlwithstring method in the Load method. That is, when we call the URLWithString method to load the URL, Let the inside of the system automatically call our custom Bx_urlwithstring method. There are comments, at this time we in our controller with urlwithstring to load the URL will be implemented in his internal one more of our own function (to determine whether the URL is nil)
Here we have implemented the use of runtime to implement internal methods of the system modification. Novice share, the big God don't like to spray.
Ios~runtime Understanding-(development interview required)