Runloop in iOS

Source: Internet
Author: User

Runloop in iOS

Usage Scenarios

1. Keep the thread alive, instead of linearly executing the task and exiting

<1> do not turn on Runloop threads

<2> Turn on Runloop threads

(1) Experiment with self to hold child threads

(2) The experiment causes the thread not to end the task to enter the death State]

(3) Event loop mode

(4) Initial attempt to use Runloop

(5) Questions arising from the first experience

Why do ① always put runloop and threads together?

② How do I create a runloop?

③ thread does not turn on Runloop by default, why does our app or the main thread still run without ending?

What are the conditions for ④runloop to function properly?

⑤ besides [Runloop run] and those methods to start runloop?

(6) Initial experience Conclusion

2. Keep the thread alive and let the thread respond to the message when we need it.

3. Have the thread perform a task (timer) on a timed basis

<1> The pit of the first Nstimer encountered

<2> use Nstimer to meet the pits

<3>nstimer caused by Viewcontroller cannot release the problem

<4>performselecter:afterdelay:

4. Monitoring observer to achieve some purpose

About the release of Runloop (the correct wording of the Runloop band Autoreleasepool)

<1> Analysis

<2> need to use the while loop to control Runloop

<3> runloop that do not require a while loop control

<4> about Autoreleasepool in the main thread

Thinking about Runloop switch mode of sub-thread

In this paper, the largest dry, sub-threading simulation of the main thread defaultmode and trackingmode switch, long code warning

Reference documents

<1>runloop

<2>autoreleasepool

Runloop in iOS

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.