Check iOS sub-thread operation UI problems, ios thread operation ui

Source: Internet
Author: User

Check iOS sub-thread operation UI problems, ios thread operation ui

In iOS development, because most functions are not thread-safe, it is very dangerous to operate the UI in the UI sub-thread. However, sometimes the UI cannot be implemented in the sub-thread due to lack of developer experience, you can also know that you did not pay attention to the code writing, or you do not know the functions that operate the UI (such as the reload function of UITableView). This problem often occurs and cannot be prevented, and iOS is not like android, once the UI is operated in the sub-thread, the system crashes directly. In iOS, the UI may only crash, leading to frequent re-occurrence of problems, and frequent crash of stacks is messy, it is a headache to find the location where the error occurred.

I wrote a simple library for Thread Check ui operations. When the sub-thread operates the ui, it will define the crash (VIEW_OP_INSPECT_CRASH) or print the stack (VIEW_OP_INSPECT_LOG_STACK) according to the macro definition (no conflict between the two ), the basic principle is to use the runtime class_replaceMethod to replace most of the uiview APIs (the get operation does not have replace considering performance issues), and then check whether the current thread is the main thread in the replace function.

Github address is https://github.com/pualxiao/PXViewOpInspect (just written a library, constantly improved, Pat. You are welcome to give comments and suggestions and participate in code improvement)

The usage is simple. h and PXViewOpInspect. m can be placed in the project. If a macro in VIEW_OP_INSPECT_CRASH and VIEW_OP_INSPECT_LOG_STACK is defined, the uiview api will be replaced. Otherwise, no.

Considering performance issues, we recommend that you use this library in debug mode. In release, VIEW_OP_INSPECT_CRASH and VIEW_OP_INSPECT_LOG_STACK are not defined.

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.