Ios~runtime Understanding-(development interview required)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.