This paper mainly introduces the concept, characteristics and application of nsrunloop.
What is nsrunloop and what is the use?
Let's look at the official definition:
"The NSRunLoop class declares the programmatic interface to objects that manage input sources. An NSRunLoop object processes input to sources such as mouse and keyboard events from the window System, NSPort objects, and c3/> objects. An NSRunLoop object also processes NSTimer events. "
The Nsrunloop type is used to manage the input source. An Nsrunloop object will handle incoming events for mouse, keyboard, Nsport object and Nsconnetion object, and of course nstimer events.
In a word, Nsrunloop is the class used to handle events.
Each thread has its own Nsrunloop object, so we don't have to create the Nsrunloop object, and if you need to, use the Currentrunloop method to get the Nsrunloop object.
Second, nsrunloop when to use
In general, the following four cases will be used in Nsrunloop,
(i) Use ports or custom input sources to communicate and other threads.
Interact with other threads using a port or a custom input source.
(ii) Use timers on the thread.
Use timers in the thread.
(c) Use any of the Performselector ... methods in a COCOA application.
Use any method that starts with Performselector.
(iv) Keep the thread around to perform periodic tasks.
Perform recurring tasks in the thread.
Third, how to use Nsrunloop
In fact, we often use the timer when using the Nsrunloop.
Nsrunloop things--Keep on updating